Assuming your string is something harder like STR10, you can easily do it like this
Code:
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
int main(void)
{
int toint;
char tostr[4] = {0};
char *src = "STR10", *pos = src;
strncpy(tostr, pos, 3);
toint = atoi(pos + 3);
printf("The string is %s\nThe number is %d\n", tostr, toint);
return 0;
}
If there's some delimiting character between the string and the number then it's way easier :-)
Code:
#include <stdio.h>
int main(void)
{
int toint;
char tostr[4] = {0};
char *src = "STR 10";
if (sscanf(src, "%s %d", tostr, &toint) == 2)
{
printf("The string is %s\nThe number is %d\n", tostr, toint);
}
return 0;
}
>>if (sscanf(somestring,"%*s%d",STRINGSIZE,tostr,&toint )==2)
For the scanf family, the * modifier means to read and discard that item, so your call reads everything up to whitespace or the end of the string and just throws it away. That's a problem with scanf and printf, their modifiers don't match and that causes confusion :-)