www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1993/03/10/17:28:49

Date: Wed, 10 Mar 93 23:21:47 +0100
From: Gordon Beaton <gordon AT Minsk DOT DoCS DOT UU DOT SE>
To: djgpp AT sun DOT soe DOT clarkson DOT edu
Subject: STRCMP (problem?)

>
>  Isn't strcmp supposed to return numbers <0,=0,>0 as results?
>

It does, at least for me. (gcc 2.2.2)

Are you really sure those are the values you're getting?
This is what I get:

strcmp("number","number") = 0 
strcmp("number","number#") = -35 
strcmp("is","what") = -14 
strcmp("was","that") = 3 

The return value seems to be the ascii value difference at the first 
character mismatch -- 'i'-'w' = -14, 'w'-'t' = 3, etc.

Have you checked that you're not doing something with another
variable that could corrupt stat? (like exceeding array bounds 
or assigning a float value to an int...)

/gordon

-----------------------------------------------------------------------------
Gordon Beaton                                               tel.   018-507405
gordon AT Minsk DOT DoCS DOT UU DOT SE                                         +46-18-507405




- Raw text -


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