need help STRCMP FUNCTION!!!

Status
Not open for further replies.

desmondlai

New Member
i having problem how to write a comparison program for my gsm modem that replying (10 79 75 13) in decimal with OK in characters ...



#include <htc.h>
#include <stdio.h>
#include "usart.h"
#include "delay.h"
#include <string.h>

int main(void)
{
//Initialize PORTD
//PD0 as Output
TRISB=0b00000000;
TRISC=0b10000000;
INTCON=0; // purpose of disabling the interrupts.
init_comms(); // set up the USART - settings defined in usart.h

char input[80] ;
int i;

PORTB =0B11111111; //PORTB0 = HIGH
DelayUs(500);
PORTB =0B00000000; //PORTB0 = LOW
DelayUs(300);


printf("at\r");
gets(input);

i= strcmp(input,"OK");******* suppose before and after OK will have (nl) and (cr).how to include the (nl)(cr) into the comparison?
if (!i)
{
RB1=1;
DelayUs(500);
RB1=0;
DelayUs(300);
printf("at+cgmm\r");
}



return 0;
}
 
Use an escape sequence

i= strcmp(input,"OK");******* suppose before and after OK will have (nl) and (cr).how to include the (nl)(cr) into the comparison?

Code:
  i = strcmp(input, "OK\x0A\x0D")

The x0A is hexadecimal for a linefeed and x0D is a carriage return.

Brad
 
Last edited:
It would probably be quicker to something like:

Code:
valid = ('O' == str[0]) && ('K' == str[1]) && (13 == str[2]) && (10 == str[3]);

Brad
 
i cant use this function because before i receive the OK for comparing there are data in front the OK so it already have few string in front...
 
Then do something like,
Code:
i=len(str);
valid=('O' == str[i-4]) && ('K' == str[i-3]) && (13 == str[i-2]) && (10 == str[i-1]);
I'm assuming gets() will only return after it receives a 0x0a.

Mike.
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…