nvm, figured it out with strtok. I think I just needed a break from the computer and some more sugar, caffeine and nicotine.
In case anyone is searching and finds this thread, this is how I did it
Code:
void parse_string(char string[], int *i, char *l)
// parses "numberchar" into two variables, one for the number, one for the character
// ty to BillyTKid
// e.g. converts 275a into 275 and a
{
int number;
char letter;
if (sscanf(string, "%d%c", &number, &letter)==2)
{
*i= number;
*l= letter;
}
else
puts("error on input");
}
void tokenize_string(char string[])
// takes in a string and tokenizes it, then passes off the individual tokens to parse_string
{
char *pch;
char character;
int number;
printf("Splitting string \"%s\" into tokens\n", string);
pch= strtok(string, "-");
while (pch!=NULL)
{
printf("%s\n", pch);
parse_string(pch, &number, &character);
printf("number is %d, character is %c\n", number, character);
pch=strtok(NULL, ">\t");
}
}
int main (int argc, const char * argv[]) {
// insert code here...
char str[]="275a -> 273b 13c";
tokenize_string(str);
return 0;
}