开发者

Problem with command Line argument in Turbo C compiler

Can anyone tell me how i can give command l开发者_如何学JAVAine argument (int argc and char*argv[]) in turbo C compiler??

Thnx


  • Launch a command prompt
  • run your executable. if it is abc.exe do : abc.exe argument1 argument2 argument3 . . . argumentn

In the code argv[0] will contain abc.exe , argv[1] will contain argument1 and so on. argc value would be the number of strings in 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:

argc = 7
argv[0] = demo.exe
argv[1] = hello
argv[2] = man
argv[3] = this
argv[4] = is
argv[5] = a
argv[6] = test

P.S.: Please stop using TurboC (3.1)


Just declare your main's prototype as int main(int argc, char *argv[]) and you'll be fine. argc and argv are passed by the operating system (whichever you're using) ;)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜