c - Ignore commas in string -
i have following code:
char dump[50]; char genre[50]; char line[300] = "can't falling in love, michael buble, pop"; sscanf(line, "%s %s %s", dump, dump, genre);
the character array "line" change every time program runs names, artist
, genre
of different song. how can make comma 1 string, when sscanf
runs, array "genre"
holds words "pop"
? right holds "falling"
since it's third word.
thanks
char genre[50]; char line[300] = "can't falling in love, michael buble, pop"; sscanf(line, "%*[^,], %*[^,], %s", genre); printf("%s", genre);//display genre
name , artist need
char name[50]; char artist[50]; char genre[50]; char line[300] = "can't falling in love, michael buble, pop"; sscanf(line, "%[^,], %[^,], %s", name, artist, genre); printf("name: %s\n", name); printf("artist: %s\n", artist); printf("genre: %s\n", genre);
Comments
Post a Comment