Click to See Complete Forum and Search --> : C code for printing command line argument


gaspacho s oup
June 5th, 2003, 02:29 AM
In C, I'm trying to have it so that if i type ./a.out <filename> in the command line, it automatically prints out the filename i entered... i am unsure as to how to do this... can someone please point me to a place that has some example code?

thanks :)

dimm_coder
June 5th, 2003, 03:11 AM
Base definition of main:
int main( int argc, char *argv[])
{
};

here argc - number of params passed to program

so

argv[0] - path of your program
argv[1] - in your case, will be a file name U gave to program
./a.out file