strcomp
Tumbler
Posts: 323
Hello
I have some troubles with a sub.
This one works:
I have some troubles with a sub.
This one works:
PUB waitOK | succes succes := false
repeat until Gsm.rxcheck < 0
if gsm.Rx == 13
if gsm.Rx == 10
if gsm.Rx == 79
if gsm.Rx == 75
if gsm.Rx == 13
if gsm.Rx == 10
succes := true
gsm.rxflush
return succes
And this one doesn't. was wondering why.
PUB waitOK | succes
succes:= false
repeat
gsm.RXstr(@Buff)
while Buff[0]== -1
if strcomp(@Buff,@ok)
succes := true
gsm.rxflush
return succes
Dat
ok Byte 13,10,79,75,13,10,0

Comments
I wrote this method for checking the presence of one string inside another -- can even specify the number of characters to scan. I use this when I am parsing commands out of longer strings.
pub strncmp(str1, str2, n) | match '' Compares n characters of str2 with str1 '' -- str1 and str2 are pointers '' -- 0 if str1 == str2, 1 if str1 > str2, -1 if str1 < str2 match := 0 if (n > 0) repeat n if (byte[str1] > byte[str2]) ++match quit elseif (byte[str1] < byte[str2]) --match quit else ++str1 ++str2 return matchAs you're providing the number of characters/bytes to compare, it will work with any two arrays of bytes.