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

Problem comparing strings

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








Problem comparing strings
PostPosted: Mon Apr 16, 2007 3:30 am     Reply with quote

Hi

I'm aware that this question might have come up before, but I am unable to find my solution. I've got a PIC16f628 interfacing to a GSM module, in my C code I send the "at" command and then receive the result (which is supposed to be 'OK') using gets().

First I declare two char arrays:

char result[40], OK[3] = "OK';

then I send

printf("at");
putc(13);

then I try to receive and put into char result[40] using

gets(result);

NOW I try to compare the following:

if((strcmp(result, OK))==0)
{
//flash some LEDs
}

However, it always flashes the LEDs even if I change the OK[3] = "OK" to something else.

I can monitor data to and from the GSM module in hyperterminal, and the "at" does get received by the module, and it DOES return the "OK" result.

Can anyone please help me?

Thanks
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Apr 16, 2007 11:53 am     Reply with quote

Debug this problem by displaying the contents of the arrays (in hex)
right before the strcmp() statement. Use two for() loops to cycle through
each element of the two arrays and use "%x" to display elements in hex.

Then look at the results and make sure that the data that you think
should be there is really there. Also make sure that the incoming
data is really a string. A string will have ASCII characters followed
by a string terminator byte of 0x00.
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