I want to split a string into tokens and save data into variables. I have the following string:
John|Doe|Melbourne|6270|AU
I need to split it by |
and every token keep as variable so I can use them in my program, like:
fname = "John"
lname = "Doe"
city = "Melbourne"
zip = "6270"
country = "AU"
tried this so far, I can access first token the rest I don't know how (besides a while loop that doesn't help me):
#include <stdio.h>
#include <string.h>
int main (void) {
char str[] = "John|Doe|Melbourne|6270|AU";
strtok(str, "|");
printf("%s\n", str);
return 0;
}