Query about odd behaviour of strspn() function


i'm trying parse input data presented in form b11=<digits>. "b11" parameter name.
to ensure i'm looking @ valid input parameter, i'm testing input (a char array in rxbuffer[]) follows:
if (strspn(rxbuffer,"b11="))==4)
but i'm getting unpredictable results. below sample input data, prefaced corresponding return value of strspn():
0 - fred (ok)
4 - b11=abc (ok)
4 - b11=012 (ok)
5 - b11=123 (eh ?)
4 - b11=234 (ok)
6 - b11=1123 (eh ?)
7 - b11=11123 (eh ?)
it seems if string starts digit '1', goes wrong. ideas ?
for reference, test code running on arduino mega 2560 board.
cheers, don

the strspn() function returns length of initial portion of str1 consists of characters part of str2. return value not length of str2, if str2 contained in str1.

so, appears output seeing reasonable.

the strspn() function not want using. want use strtok(), "=" delimiter string, "b11" portion. compare "b11" see if match. if so, call strtok() again, null first argument , "\0" second argument. token returned digits part, can pass atoi(), atol(), atof(), etc. needed.


Arduino Forum > Using Arduino > Programming Questions > Query about odd behaviour of strspn() function


arduino

Comments

Popular posts from this blog

Thread: PKI Client 5.00 install (for eToken Pro)

ATmega2560-Arduino Pin Mapping

Crossfader Arduino Tutorial