Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

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;
}
 
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.

New Articles From Microcontroller Tips

Back
Top