delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/11/02/23:36:42

Date: Sun, 2 Nov 1997 20:32:03 -0800 (PST)
Message-Id: <199711030432.UAA13680@adit.ap.net>
Mime-Version: 1.0
To: "Klywarre (THE AVATAR)" <mortral AT ix DOT netcom DOT com>, djgpp AT delorie DOT com
From: Nate Eldredge <eldredge AT ap DOT net>
Subject: Re: Newbie help

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 -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019