I would like to read a string containing a undefined amount of suffixes, all separated by ;
example 1: « .txt;.jpg;.png »
example 2: « .txt;.ods;_music.mp3;.mjpeg;.ext1;.ext2 »
I browsed the web and wrote that piece of code that doesn't work:
char *suffix[MAX]; /* will containt pointers to the different suffixes */
for (i = 0; i < MAX ; i++)
{
suffix[i] = NULL;
if (suffix_str && sscanf(suffix_str,"%[^;];%[^\n]",suffix[i],suffix_str) < 1)
suffix_str = NULL;
}
After the first iteration, the result of sscanf
is 0. Why didn't it read the content of the string?
How should be parsed a string containing an undefined number of elements? Is sscanf
a good choice?