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

strcmp problem

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



Joined: 02 Feb 2010
Posts: 345

View user's profile Send private message

strcmp problem
PostPosted: Mon Jun 08, 2015 3:05 am     Reply with quote

Hi,
Any idea why "strcmp()" in this example return "0 (False)"?
CCS C ver.4.140
Code:

#include <18F46K22.h>
#fuses HSM,PLLEN,NOWDT,NOBROWNOUT,PUT,NOPROTECT,NOCPD,NOFCMEN,MCLR
#use delay(crystal=8MHz, clock=32MHz) // HS Mode with PLLx4 (4*8MHz=32MHz)

#use RS232(DEBUGGER,rcv=PIN_C0,xmit=PIN_C0,STREAM=STREAM_MONITOR)//Debug Monitor at 2400 Default speed

#include <string.h>

void main() {

   int8 s1[]={"1234567890"};
   int8 s2[]={"1234567890"};
   
   fprintf(STREAM_MONITOR,"\n\r S1: %s",s1);
   fprintf(STREAM_MONITOR,"\n\r S2: %s",s2);
   int8 res=0;
   res=strcmp(s1, s2);
   
   if(res) fprintf(STREAM_MONITOR,"\n\r s1 = s2");
   else fprintf(STREAM_MONITOR,"\n\r s1 # s2");
   
   while( 1 ) {

   }   
}

Thanks for attention!
Ttelmah



Joined: 11 Mar 2010
Posts: 19494

View user's profile Send private message

PostPosted: Mon Jun 08, 2015 3:47 am     Reply with quote

Because it is not returning FALSE......

Read what strcmp returns. It is not 'TRUE/FALSE'.

Quote from manual:

"result is -1 (less than), 0 (equal) or 1 (greater than)".....
kmp84



Joined: 02 Feb 2010
Posts: 345

View user's profile Send private message

PostPosted: Mon Jun 08, 2015 4:57 am     Reply with quote

Ttelmah wrote:
Because it is not returning FALSE......

Read what strcmp returns. It is not 'TRUE/FALSE'.

Quote from manual:

"result is -1 (less than), 0 (equal) or 1 (greater than)".....


Thanks Mr."Ttelmah" !
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