How to pass a file name into the main Method (C/C++)
Dear All,
I wish to pass the name of a file into the main function such that the program can be called like this: programname filename. I want to write a simple program to count the number of lines of text in a text file. So the syntax should be something like: linecounter filename Any ideas please? |
how about you look at a C manual for a start? ideas such as this a pretty fundamental to C, getting to grips with them is a must.
anyway... you get the main(int argc, char **argv) line, so argc is teh number of parameters or whatever, and the argv is a pointer to the array of parameters. just access those two vairables and pull out the data you need and go willd with fopen() and such like |
cool. thanx :)
|
All times are GMT -5. The time now is 02:21 PM. |