由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Programming版 - A aimple C++ question
相关主题
为什么foo1可以而foo2不行?reverse words, not the Microsoft one!!!
菜鸟求教,一个c++的困惑Use Visual .NET for C++ programming
没有经过构造函数???C++ online Test 又一题 (转载)
请问一个exception题目这个C++程序为什么不能运行
一个古怪的C程序运行错误。关于c++的constructor的面试题
请教这个程序里用到了什么constructor啊?有几个copy constructor?C++ 初级再初级问题
[C++ boost::interprocess] 讨论贴C++菜问: 怎么这样也可以?
const 指针类型转换大侠们救命, C++ operator new 问题
相关话题的讨论汇总
话题: argc话题: argv话题: char话题: nerror话题: parameters
进入Programming版参与讨论
1 (共1页)
O***e
发帖数: 89
1
I know the meaning of argc and argv, but why argc=3 is required in many
programs, the following is an example.
#int main(int argc, char * argv[])
#{
#char chline[LINESIZE+1];
#const char * self=argv[0];
#const char * ipfile=argv[1];
#const char * opfile=argv[2];
#if ( ! (argc==3))
#{
#if (argc<3)
#cout<<"\n\nerror: too few arguments"< #if (argc>3)
#cout<<"\n\nerror: too many parameters"<
p**s
发帖数: 2707
2
I guess 3 is a magic number

【在 O***e 的大作中提到】
: I know the meaning of argc and argv, but why argc=3 is required in many
: programs, the following is an example.
: #int main(int argc, char * argv[])
: #{
: #char chline[LINESIZE+1];
: #const char * self=argv[0];
: #const char * ipfile=argv[1];
: #const char * opfile=argv[2];
: #if ( ! (argc==3))
: #{

S*********g
发帖数: 5298
3
No, you don't know the meaning of argc.

【在 O***e 的大作中提到】
: I know the meaning of argc and argv, but why argc=3 is required in many
: programs, the following is an example.
: #int main(int argc, char * argv[])
: #{
: #char chline[LINESIZE+1];
: #const char * self=argv[0];
: #const char * ipfile=argv[1];
: #const char * opfile=argv[2];
: #if ( ! (argc==3))
: #{

O***e
发帖数: 89
4
argc 包含命令行选项的个数argv 包含aygc 个C 风格字符串代表了由空格分隔的命令
选项例如对于如下命令行
prog -d -o ofile data0
argc 被设置为5
I am sure I missed something, if you know, tell me and thanks!

【在 S*********g 的大作中提到】
: No, you don't know the meaning of argc.
r****t
发帖数: 10904
5
the code says
./self ipfile opfile
so argc>=3. It is a bad UI design, though.

【在 O***e 的大作中提到】
: I know the meaning of argc and argv, but why argc=3 is required in many
: programs, the following is an example.
: #int main(int argc, char * argv[])
: #{
: #char chline[LINESIZE+1];
: #const char * self=argv[0];
: #const char * ipfile=argv[1];
: #const char * opfile=argv[2];
: #if ( ! (argc==3))
: #{

k**f
发帖数: 372
6

argc includes the program name. So argv[0] is prog in your example. With
that you have 5 command line parameters for your program.
In your earlier post, the programs you encountered happened to use 3
additional parameters. There are plenty of programs using other number of
parameters, too.

【在 O***e 的大作中提到】
: argc 包含命令行选项的个数argv 包含aygc 个C 风格字符串代表了由空格分隔的命令
: 选项例如对于如下命令行
: prog -d -o ofile data0
: argc 被设置为5
: I am sure I missed something, if you know, tell me and thanks!

O***e
发帖数: 89
7
THanks replies very much, it help much and I roughly get it.
T*****9
发帖数: 2484
8
不就是self ipfile opfile

【在 O***e 的大作中提到】
: I know the meaning of argc and argv, but why argc=3 is required in many
: programs, the following is an example.
: #int main(int argc, char * argv[])
: #{
: #char chline[LINESIZE+1];
: #const char * self=argv[0];
: #const char * ipfile=argv[1];
: #const char * opfile=argv[2];
: #if ( ! (argc==3))
: #{

E*****7
发帖数: 128
9
#if ( ! (argc==3))
这是测试在命令行执行该文件时,文件名的后面是不是带有两个参数:
C:\ExeThisCode para_1 para_2
后面:
#if (argc<3)
#cout<<"\n\nerror: too few arguments"< #if (argc>3)
#cout<<"\n\nerror: too many parameters"< 程序员要求在命令行执行该文件时文件名的后面必须带有两个参数,否则给出错信
息(参数太少,参数太多)。
O***e
发帖数: 89
10
I get it, thanks all guys.
l*****d
发帖数: 359
11
magic number is 3, command_name, input_name, out_putname, so that adds up to
three.
l*****m
发帖数: 772
12
1 (共1页)
进入Programming版参与讨论
相关主题
大侠们救命, C++ operator new 问题一个古怪的C程序运行错误。
问一个C++函数Parameter的问题请教这个程序里用到了什么constructor啊?有几个copy constructor?
一个C语言的面试题,有点乱,麻烦看一下[C++ boost::interprocess] 讨论贴
奇怪的问题:关于一个简单的malloc()小程序 (转载)const 指针类型转换
为什么foo1可以而foo2不行?reverse words, not the Microsoft one!!!
菜鸟求教,一个c++的困惑Use Visual .NET for C++ programming
没有经过构造函数???C++ online Test 又一题 (转载)
请问一个exception题目这个C++程序为什么不能运行
相关话题的讨论汇总
话题: argc话题: argv话题: char话题: nerror话题: parameters