简体   繁体   English

Turbo C 编译器中的命令行参数问题

[英]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谢谢

  • Launch a command prompt启动命令提示符
  • run your executable.运行你的可执行文件。 if it is abc.exe do: abc.exe argument1 argument2 argument3. . . argumentn如果是 abc.exe,请执行: 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.exeargv[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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM