Quantcast
Channel: MSP430 Technical Forums
Viewing all articles
Browse latest Browse all 2077

checking a character string in a buffer

$
0
0

hey guys working on reading a config file and parsing it.

 

so i read some number of bytes into a buffer (64 byte long)

 

is there an easier way to test is the bytes read match a given string.

 

currently I have to do this

*read bytes*
if (Line[0] == '[' && Line[1] == 's' && Line[2] == 't' && Line[3] == 'a' &&
                            Line[4] == 'r' && Line[5] == 't' && Line[6] == ' ' && Line[7] == 'c' &&
                            Line[8] == 'o' && Line[9] == 'n' && Line[10] == 'f' && Line[11] == 'i' &&
                            Line[12] == 'g' && Line[13] == ']'){
                            printf("it matches");
                        }

this works but is a pain in the butt to work with.

 

but what I would like to do is something more like this

*read bytes*
if (Line == '[start config]'){
printf("it matches");
}

but this fails because "Line" is a 64 byte long buffer and I only read 14 bytes into it, so the rest of the garbage space is still there.

 

does this make sense?  I know how many bytes i read into it is there someway to make it only test x number of bytes from a buffer when testing for equality? or some other thing I can't even thing of.


Viewing all articles
Browse latest Browse all 2077

Trending Articles