Hi, this got to do with command line arguments, the following is my code:
#include %26lt;stdio.h%26gt;
main( int argc, char *argv[] )
{
if( argc %26gt; 5 || argc %26lt; 2){
printf("Usage: spellcheck [-case] [-caps] [dictionary-filename] filename", argv[1]);
exit(2);
}
if(strcmp(argv[2], "-peter") == 0){ *****
printf("Hello world\n");
}
return 0;
}
What's wrong with the **** line here? The program doesn't compile.
C programming question, please help?
What is the error?
But, it looks like you need to include #include %26lt;string.h%26gt; so that the strcmp function can be found.
Reply:== is the equality operator, meaning "the same as". Your code sez: if Object is the same as Zero, when perhaps you mean
if(strcmp(argv[2], '-peter') = 0) {
// ? for false ?
I will just comment, I see a lot of if statements trying to compare Object, when you are testing for state, eg in C++ boolean is a primitive and not an Object (an array is an Object) and therefore, the Object will never equal Zero (or boolean false).
I don't remember if this works in C...
if(strcmp(argv[2], "-peter") = !0{ // not false
if(strcmp(argv[2], "-peter") != 0{ // not sure if this is always true, I think it is.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment