I need this simple split
Item one, Item2, Item no. 3,Item 4
>
Item one
Item2
Item no.3
Item 4
%*[, ]
format in scanf to ignore comma and spaces, but this is not accurate: the separator should be exactly one comma optionally followed by spaces.Do I really need regex here, or is there any effective short way to encode this?
How about something like:
char inputStr[] = "Item one, Item2, Item no. 3,Item 4";
char* buffer;
buffer = strtok (inputStr, ",");
while (buffer) {
printf ("%s\n", buffer); // process token
buffer = strtok (NULL, ",");
while (buffer && *buffer == '\040')
buffer++;
}
Output:
Item one
Item2
Item no. 3
Item 4
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With