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.

string in c18 compiler

Status
Not open for further replies.

td micro

Member level 5
Member level 5
Joined
Jun 26, 2012
Messages
86
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,286
Activity points
1,929
hi...
in my project, i have to read string from pc to USART in PIC 18F. we are using C18 compiler. and then we have to compare it with one predefined string.
i saw
getsUSART(a,7); but in this, we have to add exact 7 characters.but the length of the string is unknown..so how can we read one string with unknown length?
and how to compare it with predefined string? plz help me.....
thank you
 

Hai,
If the length of the string is unknown, you can use getcUSART() to read a single byte.
You can either write an ISR for reading bytes from UART or use the function in a loop (it should contiuously read whenever the data is ready).
The byte received should be stored to a buffer and increment the index of the buffer to store the next byte.
Data transfer can be paused, either when the buffer is full or after a timeout period.

You can compare the strings using strcmp() function,which is in string.h file
 

hi,
thanks for reply
You can compare the strings using strcmp() function,which is in string.h file

i think, we cant compare like this
strcmp(buffer[], "hallooo");
by using strcmp, we cant compare with one predefined string.so can you please help me to compare whether the input string is "hallooo"
 

Hai,
Did you tried type casting the parameters of strcmp() as const char* or rom unsigned char*.

Otherwise you can write a function like this pseudo code:

Code:
int fn(char* b1,char* b2)
{
    while((*b1 != '\0') && (*b2 != '\0))
   {
     if(*b1 != *b2)
       return false;
    b1++;
    b2++;
   }
  return true;
}
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top