Looking for suggestions on how to use multiple delimters on a string
Hello.. So this is my first post. I've browsed on here before, but now I decided to try and get some help instead of racking my brain, wasting time and getting nowhere in some cases. I've read all the rules and guidelines before posting.
This is part of a bigger program im working on that deals with data structures, but I'm trying to figure out a way to tokenize a long file of purchases that is being read to my program. I rewrote the program to pinpoint my problem. I need to get the name, cost, item and quantity from this string. I figured out how to look for the cost, but what about the name and item(shirts)? How can I do this all in one loop because there are multiple strings and i'm gonna eventually send all the info to a data structure for each person(name)? I'm only asking about the tokenizing part, but this code works for the cost. Thanks!
Code:
int main(void) {
char myString[] = "Angela bought 9 shirts for $6 each." ;
char * del = " " ;
char * token ;
// this token gets the cost for each string
token = strtok(myString, del) ;
while(token!= NULL) {
if(token[0] == '$') {
token = strtok(token, "$") ;
printf("%s\n", token) ;
}
token = strtok(NULL, del) ;
}
}