Archived

This topic is now archived and is closed to further replies.

Elite19

What is the command line?

Recommended Posts

Hi, this should probably be in the beginners forum but here goes anyway. I am reading various documents about programming apps that read a file at start up and perform certain functions. The book I''m reading keeps refering to the command line. Eg, If the user runs program x with no command line arguments the program will exit. Is it some sort of initialization process or something? If someone could elaborate on command lines that would be a great help. Sorry if this sounds like a stupid question, Thanks

Share this post


Link to post
Share on other sites
the command line is the things you write after a program name
eg: tar -x -v -f archive.tar
that command runs the program "tar" with 4 command line arguments.

In your program, the command line arguments are defined as follow


#include <stdio.h>
int main(int argc, char *argv[])
{
// argc is the number of argument (including the executable)
// so with the example above it would be 5
// argv[0] is "tar"
// argv[1] is "-x"
// up to argv[argc - 1]
// if you want to list all command line arguments, simply do
int i;
for(i=0; i<argc; i++)
printf("argument #%d: %s\n", i, argv);

return 0;
}


[edited by - lemurion on October 8, 2003 12:06:02 PM]

Share this post


Link to post
Share on other sites