September 8th, 2012, 04:02 AM
Now working program
hello, i'm not familiar with the programming, but i'm must become beacause i have to go in for an examination :(
Here's my problem: this program is written in my textbook, but the only result i receive is this message: "Usage: find <filename> <ch>". Is this all that must be displayed?
int main(int argc,char *argv)
printf("Usage: find <filename> <ch>\n");
printf("Cannot open file.\n");
September 8th, 2012, 04:40 AM
No. If you think that you are doomed as far as any examination is concerned. Most examinations occur at the end of a course of lessons - how come you have got to the examination without the lessons!?
Originally Posted by q1cet0o
Read the code, or just follow the instructions. The message output is telling you how to run the code. It is obviously asking you to provide a filename and a character as command line arguments. That is not a programming issue, that is a fundamental aspect of using a computer.
If you are running the code from the command line, you need to provide two arguments, e.g.:
find somefile.txt x
then if somefile.txt exists and contains a 'x' character, a "found" message will be output. If somefile.txt does not exist, the "cannot open" message will be output.
If you are running the code from some IDE, it will probably have a place in the project or debug configuration where you can add test arguments.
September 9th, 2012, 02:49 AM
Note your Argument Count (argc) also takes in the count of your Program File Name.
Ex: if the file in which this program is written is named Program.c.
Your Command line should look like
"Program.c filename.txt x" here your argc is 3.
In simple argc also takes in the profram file name as its input!!
Hope this helps you to determine the output.
September 9th, 2012, 04:41 AM
C is not a scripting or interpreted language - you cannot run a .c file! An executable generated from a sourcefile called Program.c can have any name, of which Program.c is most unlikely!
Originally Posted by pratster
It is clearly implicit in the question the executable name in this case is "find" so this is just an inaccurate and unnecessary duplicate of my answer.
September 9th, 2012, 07:07 AM
Oops! Yeah i didn't notice that "find" must be an executable on the cmd interface!
Misinterpreted it to be the argument(filename)!
Thanks for letting me know.
September 9th, 2012, 09:02 AM