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 support@ccsinfo.com

Need help with comparing strings

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
frierray



Joined: 11 Nov 2008
Posts: 29

View user's profile Send private message

Need help with comparing strings
PostPosted: Tue Nov 11, 2008 4:41 pm     Reply with quote

I am a little new to C programming and I need to compare two ASCII arrays. One is pw and the other is k_buff.

I tried the following and it works for the first two locations in the array and the last, but not the third.

Is there a better way to compare the two arrays?
Code:

if (pw[0]==k_buff[0],pw[1]==k_buff[1],pw[2]==k_buff[2],pw[3]==k_buff[3])
   printf("\r\n\PW OK\r\n ");             // Print message
else
   printf("\r\n\PW ERROR\r\n ");             // Print message
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Nov 11, 2008 5:08 pm     Reply with quote

Use strcmp() for ASCII strings and memcmp() for non-string arrays.
Wayne_



Joined: 10 Oct 2007
Posts: 681

View user's profile Send private message

PostPosted: Wed Nov 12, 2008 3:22 am     Reply with quote

Or in the case your char arrays (string) is not null terminated use
strncmp
frierray



Joined: 11 Nov 2008
Posts: 29

View user's profile Send private message

PostPosted: Wed Nov 12, 2008 10:39 am     Reply with quote

Thanks for the feedback, it's a big help. I did use memcmp and it worked great. I'll also have a look at strncmp.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
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