[英]Problem with command Line argument in Turbo C compiler
Can anyone tell me how i can give command line argument (int argc and char*argv[]) in turbo C compiler??谁能告诉我如何在 turbo C 编译器中提供命令行参数(int argc 和 char*argv[])?
Thnx谢谢
abc.exe argument1 argument2 argument3. . . argumentn
abc.exe argument1 argument2 argument3. . . argumentn
abc.exe argument1 argument2 argument3. . . argumentn
In the code argv[0]
will contain abc.exe
, argv[1]
will contain argument1
and so on.在代码中
argv[0]
将包含abc.exe
, argv[1]
将包含argument1
等等。 argc
value would be the number of strings in argv
argc
值将是argv
中的字符串数
Sample样本
#include <stdio.h>
int main (int argc, char *argv[])
{
int i=0;
printf ("\nargc = %d", argc);
for (i=0; i<argc; i++)
{
printf ("\nargv[%d] = %s", i, argv[i]);
}
printf ("\n");
return 0;
}
run with:运行:
demo.exe hello man this is a test
Output: Output:
argc = 7
argv[0] = demo.exe
argv[1] = hello
argv[2] = man
argv[3] = this
argv[4] = is
argv[5] = a
argv[6] = test
PS: Please stop using TurboC (3.1) PS:请停止使用 TurboC (3.1)
Just declare your main's prototype as int main(int argc, char *argv[])
and you'll be fine.只需将 main 的原型声明为
int main(int argc, char *argv[])
就可以了。 argc and argv are passed by the operating system (whichever you're using);) argc 和 argv 由操作系统传递(无论您使用哪个);)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.