Mail Archives: djgpp/1997/11/02/23:36:42
At 10:35 11/1/1997 -0800, Klywarre (THE AVATAR) wrote:
>Hello all, I'am trying to work with a test program in C, so far it's
>working *somewhat*. First the code, then what is **not** working.
>
>#include <stdio.h>
>#include <stdlib.h>
>#include <string.h>
>
>// The following two lines are only temp's.
>int fileflag = 1;
>char filename[] = "DUMMY.MAP";
>
>void main(int argc, char *argv[])
>{
> if(argc == 2)
> if(strcmp(argv[1], "\\c"))
[snipped]
>>main \(any character will do -- tested)
> when any character is used after the '\' character, the
>message to enter a file name appears ---- not what it's supposed to
>do!!! only when the option is '\c'.
Yes. Your problem is that `strcmp()' returns 0 if the strings are the same,
and nonzero if they differ. One would expect it to return a standard 1/0
true/false flag, but it doesn't. So that line wants to say:
if(strcmp(argv[1], "\\c") == 0)
I find it helps to think of strcmp as subtraction: It subtracts the second
arg from the first, and returns the difference. Greater than 0 if arg1 was
bigger, less if arg1 was less, and 0 if they are equal.
Nate Eldredge
eldredge AT ap DOT net
- Raw text -