Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[SOLVED] How to copy a particular char from char string to a single char

Status
Not open for further replies.

Mrunal Ahirrao

Full Member level 2
Joined
Nov 26, 2012
Messages
133
Helped
2
Reputation
4
Reaction score
2
Trophy points
1,298
Location
India
Activity points
2,213
I am trying to work with PIC and GSM communication. In that as a notification after receieving SMS GSM sends string as:+CMTI: "SM",5.
So I want to copy that '5' in a char. But though copying it the value in the char becomes garbage value and not '5'. Here is the code snippet:
Code:
char SMSL; // this char is to be used to store the '5'
char RXD[55];// this array is used to store strings from GSM

//this is the logic I am using (is it correct?)
//including CR and LF the place of '5' will be at RXD[14]

SMSL=RXD[14];

Now the SMSL should contain '5' isn't it? but it is not. It shows up some random chinese alphabet when seen on 2x16 LCD! Experts please guide me.
 

Something like that:
Code:
unsigned char txt[] = "some garbage text N=5 sample text";
unsigned char txt_cnt;
Code:
  txt_cnt = SearchForString("N=", 2, txt, sizeof(txt));
  txt_cnt = txt[txt_cnt+2] - '0';
txt_cnt = 5
Where:
Code:
unsigned char SearchForString (unsigned char * StringToSearch, 
                               unsigned char StringToSearchLen, 
                               unsigned char * TextString,
                               unsigned char TextStringLen)
{
  unsigned char Res;
  for (Res = 0; Res != (TextStringLen - StringToSearchLen); Res++)
  {
    if (StringsCompareByLen(StringToSearch, TextString + Res, StringToSearchLen) == 0)
      return Res;
  }
  return 0xFF;
}
And
Code:
unsigned char StringsCompareByLen (unsigned char * String1, unsigned char * String2, unsigned int Len)
{
	unsigned int Diff = 0;
	while(Len--)
		if (*String1++ != *String2++) Diff++;
	return Diff;
}
 
1st see what RXD contains after receiving character string.whether it is correct response or not
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top