中国DOS联盟论坛

China DOS Union

-- Unite DOS · Advance DOS · Grow DOS --
Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum
Guest | Log in | Register | Members | Search | China DOS Union
中国DOS联盟论坛
The time now is 2026-08-07 00:56
48,040 topics / 350,125 posts / today 1 new / 48,252 members
DOS批处理 & 脚本技术(批处理室) » Those who know both DOS and C/C++, please come in
Printable Version  750 / 6
Floor1 ssyfzy Posted 2007-10-13 16:02
初级用户 Posts 27 Credits 64
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
Floor2 scriptor Posted 2007-10-14 01:22
银牌会员 Posts 555 Credits 1,187
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
Floor3 ssyfzy Posted 2007-10-14 06:44
初级用户 Posts 27 Credits 64
That has nothing to do with it, does it?
Floor4 scriptor Posted 2007-10-14 07:14
银牌会员 Posts 555 Credits 1,187
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!
Floor5 ssyfzy Posted 2007-10-14 09:38
初级用户 Posts 27 Credits 64
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 ]
Floor6 zhclsy Posted 2007-10-14 15:35
初级用户 Posts 34 Credits 83
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!
Floor7 ssyfzy Posted 2007-10-14 17:10
初级用户 Posts 27 Credits 64
Help?
Come on, does this count as helping?
He has a problem, so I'll help him, all right!!!
[ Contact the Union admin team - 中国DOS联盟 - Standard version ]
Sponsored by ifanr Inc | © 2001–2023