View previous topic :: View next topic |
Author |
Message |
art
Joined: 21 May 2015 Posts: 181
|
Strcmp problem |
Posted: Fri Jun 05, 2015 1:15 am |
|
|
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
|
|
Posted: Fri Jun 05, 2015 1:50 am |
|
|
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
|
|
Posted: Fri Jun 05, 2015 2:14 am |
|
|
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
|
|
Posted: Fri Jun 05, 2015 2:34 am |
|
|
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
|
|
Posted: Fri Jun 05, 2015 4:05 am |
|
|
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
|
|
Posted: Fri Jun 05, 2015 1:01 pm |
|
|
Late V4, and all V5. |
|
|
|