c++ - Split string into string and int -
i trying use sscanf(inputcmd, "%s%d", cmd, value);
convert string inputcmd
string cmd
, , int value
in arduino sketch. isn't working, apparently variables wrong type (string, instead of char*)
inputcmd in format foo90, , neither length of number or string can assumed constant. best way separate 2 parts of inputcmd
, store them in 2 variables? cmd
should foo, , value
should 90.
thanks.
besides problem string
versus char*
, scanf
format "%s"
reads space-delimited string. if there's no space between string , number can't use sscanf
.
as possible solution can attempt substring of each part of input string, , number-part convert int
.
to find out length of first substring (which should put cmd
) , starting position of number, need iterate on characters of string until find non-alphabetic character.
Comments
Post a Comment