+ 5
[Solved] C string tokenizer with space delimiter does not work as expected on SL code playground with user provided input.
13 ответов
+ 8
scanf() is designed to stop reading in characters when it encounters a whitespace character. If you use fgets() instead of scanf() in the first example, it works just as fine.
+ 7
Martin Taylor thanks. I didn't know about %*c
+ 6
Coder Kitten I didn't know that option. Thanks!
+ 5
I was trying to test the code in the above question with space delimited words as input from the SL code playground input but the tokenizing didn't work as I expected. Any ideas on what I may be doing wrong?
+ 5
Shadow brilliant! Thanks.
+ 4
On the other hand, if I provide the string to be tokenised within the code itself, it works.
https://code.sololearn.com/cZLyNIM4ETvY/?ref=app
+ 4
It might be because of scanf. Try to get a whole line instead. (try with gets, maybe?)
+ 3
Sonic indeed, I didn't see the Shadow answer... 😅 Sorry! (I think I was writing at the moment Shadow answered).