I have a file that i want to read from in c, the file's format is as follows :
<city> <pokemon1> <pokemon2>; <near_city1> <near_city2>
for example: paris pidgey pikachu; london berlin
I want to be able to cut this row into tokens using strtok, but for some reason its not working properly.
My code: lets say I have this row read from the file using fgets and put into char* row. so what I did was :
char* city_name = strtok(location_temp, " "); // to receive city
char* pokemons_names = strtok(strtok(location_temp, " "),";");
Although , this code brings segmentation fault later on, so I followed the debugger and noticed that the second code line is not being executed properly.
Help ?
You can use
strtok()
like this to gather your information about each line:Output:
It really depends how your storing these strings though.