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

string comparison

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



Joined: 08 Mar 2008
Posts: 17

View user's profile Send private message

string comparison
PostPosted: Sun Apr 26, 2009 12:32 pm     Reply with quote

I am not that versed in c programming.

I am trying to take input from an rs232 connection and compare it to a string constant (a word).

This example does not compile....it is my understanding the I compare the string from the 'gets' and compare it to the constant. I have even tried strcmp ("word","word")...I am clearly not understanding something.

Someone please set me on the right course.

Thanks a million.

Code:

#include <16F690.h>
#fuses INTRC_IO, NOWDT, NOBROWNOUT, PUT, NOMCLR
#use delay(clock=8000000)
#use rs232(baud=4800, xmit=PIN_B7, rcv=PIN_B5)


#include <string.h>
//=============================
void main()
{
char input[6];
int x;
printf("Password: ");
while(1)

  { gets(input);

    puts(input);
 x = strcmp(input, "word");
if (x == 0)
    printf ("strings are the same \n\r");

   printf ("password typed is %s. \n\r",input);



  }

}
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sun Apr 26, 2009 12:52 pm     Reply with quote

Read this thread. It has two solutions.
http://www.ccsinfo.com/forum/viewtopic.php?t=34302
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