I am having problems using the strsep()
function in C. I want to split a string into two parts. The string contains info about the currently playing song, in ARTIST - TITLE
format, so artist and title are separated by one space, one dash and again one space. I want to separate it by this, " - ". "-" won't work because some artists have a dash in their name.
When I try this code with, for example, "Michel Telo - Ai Se Eu Te Pego":
// String is in tmp
while ((token = strsep(&tmp, " - ")) != NULL)
{
printf("%s\n", token);
}
I get this:
[root@runeaudio ~]# ./board
Michel
Telo
Ai
Se
Eu
Te
Pego
Instead of this:
[root@runeaudio ~]# ./board
Michel Telo
Ai Se Eu Te Pego
Seems like strsep()
is dividing delimiter into 3 characters: " ", "-", " " and using OR between them, but I want it to look for " - " as it is. Any idea how to fix this?