 |
 |
| View previous topic :: View next topic |
| Author |
Message |
Ttelmah
Joined: 11 Mar 2010 Posts: 20061
|
|
Posted: Wed May 18, 2016 2:53 am |
|
|
We are back to the thing I mentioned earlier in the thread of getting a basic C textbook.....
If you look at the manual, it says:
| Code: |
cresult=strcmp (s1, s2)
//then further down:
result is -1 (less than), 0 (equal) or 1 (greater than)
|
It does an alphabetic compare between the strings. Returning '0' if they match, or a signed value -1 or 1 if they are alphabetically less, or greater than one another. Note _signed_.
The string compare function, is a standard C library function, and this would be covered in a C textbook.
strcoll, only applies to machines running with things like Unicode, where the compare is done using the selected 'locale'.
Key thing missing in your code, is an understanding of the size of strings. "hola", is not 4 characters long. It is 5. A string in C, always has a NULL terminator character. When you read 'hola' back with get_string, you will only actually get 'hol', since you only have a 4 character buffer.
get_string gets a string no longer than the specified 'max', so will not be returning the fourth character (it knows it has to save this for the NULL).
I'd suspect this is why things are not working, since if you then compare this, it will not match 'hola'..... |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|