China DOS Union

-- Unite DOS · Advance DOS · Grow DOS --

Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum
DOS stands for freedom, openness and progress. Let us work hard, learn from the openness and GNU spirit of FreeDOS and Linux, and together build and grow a free GNU GPL world!

中国DOS联盟论坛
The time now is 2026-08-07 01:53
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » Those who know both DOS and C/C++, please come in View 751 Replies 6
Original Poster Posted 2007-10-13 16:02 ·  中国 黑龙江 哈尔滨 教育网
初级用户
Credits 64
Posts 27
Joined 2007-10-03 11:01
18-year member
UID 98818
Gender Male
Status Offline
How can I save data from DOS into variables in C/C++?

For example, the result of dir /b
Or in for %f in (*.txt) do ...., assigning %f to a C/C++ variable

The premise is not using file redirection
Floor 2 Posted 2007-10-14 01:22 ·  中国 北京 中国科学院研究生院玉泉四公寓
银牌会员
★★★
Credits 1,187
Posts 555
Joined 2006-12-21 07:35
19-year member
UID 74129
Gender Male
Status Offline
C file operations should work

Because there is the argv parameter, it can accept external input, right?
Take a look at how argv is used

Teacher Tan's book should explain it
Or any other C language book should also talk about argv in file operations
Floor 3 Posted 2007-10-14 06:44 ·  中国 黑龙江 哈尔滨 教育网
初级用户
Credits 64
Posts 27
Joined 2007-10-03 11:01
18-year member
UID 98818
Gender Male
Status Offline
That has nothing to do with it, does it?
Floor 4 Posted 2007-10-14 07:14 ·  中国 北京 中国科学院研究生院玉泉四公寓
银牌会员
★★★
Credits 1,187
Posts 555
Joined 2006-12-21 07:35
19-year member
UID 74129
Gender Male
Status Offline
Originally posted by ssyfzy at 2007-10-14 06:44:
That has nothing to do with it, does it?



Take a look at this!

The command-line parameters argc and argv in C
The command-line parameters argc and argv in C

The command-line parameters argc and argv in C
Keywords: argc,argv
main(int argc,char **argv)
argv is a pointer to a pointer
argc is an integer
char **argv or: char *argv or: char argv
The notation inside the parentheses of main() is fixed.

Here is an example to understand how these two parameters are used:

Suppose the name of the program is prog,

If you only input prog, then the parameters passed by the operating system are:

argc=1, meaning there is only the program name.
argc has only one element, and argv points to the input program path and name: ./prog

If you input prog para_1, there is one parameter, then the parameters passed by the operating system are:

argc=2, meaning that besides the program name there is one more parameter.
argv points to the input program path and name.
argv points to the parameter string para_1.

If you input prog para_1 para_2, there are 2 parameters, then the parameters passed by the operating system are:

argc=3, meaning that besides the program name there are 2 more parameters.
argv points to the input program path and name.
argv points to the parameter string para_1.
argv points to the parameter string para_2.


There may be a little difficulty when actually calling it
This hasn't been tested, I don't have C
You can try it yourself

Try passing it with a pipe, don't come here acting all disdainful,
some questions, to begin with, nobody would be willing to answer
You should know that!
Floor 5 Posted 2007-10-14 09:38 ·  中国 黑龙江 哈尔滨 联通
初级用户
Credits 64
Posts 27
Joined 2007-10-03 11:01
18-year member
UID 98818
Gender Male
Status Offline
That has nothing to do with it, too!

If you don't understand, can you be a bit modest? Showing off the most basic stuff in C?
Too bad it has nothing to do with the question, and you made a complete fool of yourself!

[ Last edited by ssyfzy on 2007-10-14 at 09:41 AM ]
Recent Ratings for This Post ( 1 in total) Click for details
RaterScoreTime
HAT -8 2007-10-15 07:10
Floor 6 Posted 2007-10-14 15:35 ·  中国 江苏 苏州 昆山市 联通
初级用户
Credits 83
Posts 34
Joined 2007-10-14 13:49
18-year member
UID 99713
Gender Male
Status Offline
That has nothing to do with it, too!

If you don't understand, can you be a bit modest? Showing off the most basic stuff in C?
Too bad it has nothing to do with the question, and you made a complete fool of yourself! ---------------------------------------->that's just sb

OP, you're really damn awesome!

['Reply #4']: Brother, thanks for the hard work. Don't help this kind of person again in the future!
Floor 7 Posted 2007-10-14 17:10 ·  中国 黑龙江 哈尔滨 教育网
初级用户
Credits 64
Posts 27
Joined 2007-10-03 11:01
18-year member
UID 98818
Gender Male
Status Offline
Help?
Come on, does this count as helping?
He has a problem, so I'll help him, all right!!!
Recent Ratings for This Post ( 1 in total) Click for details
RaterScoreTime
knoppix7 -4 2007-10-14 18:00
Forum Jump: