CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

Read characters from uart using RS232
Goto page Previous  1, 2, 3, 4
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
Ttelmah



Joined: 11 Mar 2010
Posts: 20061

View user's profile Send private message

PostPosted: Wed May 18, 2016 2:53 am     Reply with quote

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'.....
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Goto page Previous  1, 2, 3, 4
Page 4 of 4

 
Jump to:  
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