0

Can anyone tell me how i can give command line argument (int argc and char*argv[]) in turbo C compiler??

Thnx

2 Answers 2

6
  • 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)

Sign up to request clarification or add additional context in comments.

2 Comments

Why do you print backwards ("\nstuff" versus "stuff\n")? :D
habit, "stuff\n" feels like that there is no soil under the feet of the string. "\nstuff" feels like there is a solid base (the \n) behind the string protecting it. Its actually mental.
0

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) ;)

2 Comments

maybe he was a windows fan :)
@Andrei: ops.. Do they still exist? :P Never mind, will change it =)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.