Hey Im having a problem trying to parse strings. My program can receive 4 types of input:
s = "x=10+2;"
s = "x=10+y;"
s = "x=y+10;"
s = "x=y+z;"
I mean the format is something like: s = "(string)=(string)||(int)+(string)||(int);"
I have tried to use sscanf( s, "%c=%d+%d", &c, &v1, &v2 )
but I need to first verify which type of input is it.
char* s = "x=2+22;";
int v1, v2;
char* c;
sscanf( s, "%c=%d+%d", &c, &v1, &v2 );
printf("%s %d %d\n", c, v1, v2);
I want to parse the string to three vars.
Let me propose you another way, using
strsep
and someif
conditionals to detect if the characters are integer or string, the following code works for all your cases