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

Error using strcmp()

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



Joined: 12 Mar 2008
Posts: 5

View user's profile Send private message

Error using strcmp()
PostPosted: Wed Apr 09, 2008 7:34 am     Reply with quote

I am having an error whenever I use the strcmp function. Any help would be appreciated.
Code:
#include <18F4520.h>
#fuses   HS,NOLVP, NOWDT
#use   delay(clock = 20000000)
#use   rs232 (baud=9600, xmit=PIN_C6, rcv=PIN_C7)

#include <string.h>   // for strcmp()

#define PUSH_BUTTON   PIN_A4

void wait_for_one_press(){
   while(input(PUSH_BUTTON));
   delay_ms(100);   // switch de-bounce
   while(!input(PUSH_BUTTON));
}

void BR_get_string(char *s){   //blue radio get string
   char   input;

   input = getc();   // <CR>
   getc();   // <LF>
   input = getc();      // message<CR>   NOTE: <CR> is not put into the array.
   input = getc();;   // <LF>
}

void main(){
   char   myStr[25];   // make this only as big as the longest message plus one for the null character '\0'

   while(TRUE)
   {
      wait_for_one_press();

      printf("ATSW25,1,1,0,0\r");
      BR_get_string(myStr);
      if (strcmp(myStr, &"OK"))
         continue;

      printf("ATDM,00A096141292,1101\r");
      //BR_get_string(myStr);
      //if (strcmp(myStr, &"CONNECT,00A096141292"))
      //   continue;

      //printf("+++\r");
      //BR_get_string(myStr);
      //if (strcmp(myStr, &"OK"))
      //   continue;

      //printf("ATEDSCO\r\n");
   }
}


At the line
Code:
if (strcmp(myStr, &"OK"))

and the other places in the comments above, I get the error:
Quote:
Expecting an identifier
meereck



Joined: 09 Nov 2006
Posts: 173

View user's profile Send private message

PostPosted: Wed Apr 09, 2008 7:47 am     Reply with quote

hi, you need to have a string in RAM if you want to use STRCMP function on it.
I usually do smthg like this:
Code:

char tempbuf[10];
sprintf(tempbuf,"OK");
if(strcmp(receivecharacterbuffer,tempbuf)!=0) printf("different");

see this to understand what strcmp returns : http://www.elook.org/programming/c/strcmp.html
boham



Joined: 12 Mar 2008
Posts: 5

View user's profile Send private message

PostPosted: Wed Apr 09, 2008 7:53 am     Reply with quote

No errors! Thank you very much. I'll see later on how it runs in the PIC
Matro
Guest







PostPosted: Wed Apr 09, 2008 8:01 am     Reply with quote

Another way to make it work...

I take the following "line" as an example but all similar lines have the same problem :
Code:

(strcmp(myStr, &"OK"))

First, to use constant strings, you need to add in your code :
Code:

#device PASS_STRINGS = IN_RAM

And then the '&' shall not be present :
Code:

(strcmp(myStr, "OK"))


Now it should work.

Matro.
boham



Joined: 12 Mar 2008
Posts: 5

View user's profile Send private message

PostPosted: Wed Apr 09, 2008 11:02 am     Reply with quote

Allrighty... The code looks just to me but I think the direction I am going is not right.

The radio I am controling receives a command and replies with an OK status if everything is good.

I can command this thing all day long but it seems that I cannot check for that OK reply.

Quote:
Sent : ATSW25,1,1,0,0<cr> // Set ConnectMode Master & data mode
Reply:<cr_lf>OK<cr_lf>

Is what I am trying to accomplish.

The above code works if I do not try to invoke the
BR_get_string(myStr);
command.

What I want to do is take that reply and continue if the reply is
<cr_lf>OK<cr_lf>
and not continue otherwise.
meereck



Joined: 09 Nov 2006
Posts: 173

View user's profile Send private message

PostPosted: Wed Apr 09, 2008 11:21 am     Reply with quote

Matro wrote:
Another way to make it work...

First, to use constant strings, you need to add in your code :
Code:

#device PASS_STRINGS = IN_RAM

It probably doesnt work with v3 compilers, does it?
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Apr 09, 2008 11:40 am     Reply with quote

That's right. It requires vs. 4 to work.
In vs. 3, you have to copy the string to a RAM array with explicit code.
ftrax



Joined: 24 Sep 2013
Posts: 22
Location: EspaƱa

View user's profile Send private message

PostPosted: Fri May 08, 2015 5:02 am     Reply with quote

thank you very much Matro, I've been looking for any instruction like this for a long time, thank you very much !!
Very Happy Very Happy
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