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
art



Joined: 21 May 2015
Posts: 181

View user's profile Send private message

Strcmp problem
PostPosted: Fri Jun 05, 2015 1:15 am     Reply with quote

I have problem regarding strcmp function. It is not working, can anyone help to solve this problem.

Code:

#include <18F452.h>
#fuses HS,NOWDT,NOPROTECT,NOLVP
#use delay(c20000000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7)
#include <stdio.h>
#include <string.h>
 
void main()
{
char x[8];

while(true)
  {

      printf("Enter number:  \n");
      get_string(x,8);

       
      if (strcmp(x, "123") == 0)
           output_B(0b00000111)

      if (strcmp(x, "0") == 0)
           output_B(0b00000111)
       
    }

}
Ttelmah



Joined: 11 Mar 2010
Posts: 19548

View user's profile Send private message

PostPosted: Fri Jun 05, 2015 1:50 am     Reply with quote

First basic things:
1) Learn to use the code buttons.....
2) When using the hardware RS232, you should _always_ have 'ERRORS' in the RS232 declaration, unless _you_ have added your own error handler.
3) You are not including input.c, so the code as posted won't compile..... :(
4) Same applies to missing semi-colons on some code lines.

Then:
3) Read the manual. What does it say about S1, and S2?. Look at ex_str.c. How do they use the functions?. Do a search here. 'Why' has been explained many times.
It is actually possible to use constants on current compilers. Look at what the option 'PASS_STRINGS=IN_RAM' does.

So:
Code:

#include <18F452.h>
#device PASS_STRINGS=IN_RAM
#fuses HS,NOWDT,NOPROTECT,NOLVP
#use delay(crystal=20MHz)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7, ERRORS)
#include <stdio.h>
#include <input.c>
#include <string.h>

void main()
{
   char x[8];
   
   while(true)
   {
      printf("Enter number: \n");
      get_string(x,8);

      if (strcmp(x, "123") == 0)
         output_B(0b00000111);

      if (strcmp(x, "0") == 0)
         output_B(0b00000111);
   }
}
art



Joined: 21 May 2015
Posts: 181

View user's profile Send private message

PostPosted: Fri Jun 05, 2015 2:14 am     Reply with quote

Thank you for your reply, but when i write #device PASS_STRINGS=IN_RAM , it will reply 'extra characters on preprocessor command line'. What does it mean?
Ttelmah



Joined: 11 Mar 2010
Posts: 19548

View user's profile Send private message

PostPosted: Fri Jun 05, 2015 2:34 am     Reply with quote

Almost certainly that you have an old compiler that does not accept this.

So you have to use strcmp, as is shown in the example. Look at it. Your compiler does not support this option.
art



Joined: 21 May 2015
Posts: 181

View user's profile Send private message

PostPosted: Fri Jun 05, 2015 4:05 am     Reply with quote

Thank you for your reply. Do you know what is the compiler version that can use #device PASS_STRINGS=IN_RAM ?
Ttelmah



Joined: 11 Mar 2010
Posts: 19548

View user's profile Send private message

PostPosted: Fri Jun 05, 2015 1:01 pm     Reply with quote

Late V4, and all V5.
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