+ 1
How to read a paragraph with white spaces using scanf function in c language.?
3 odpowiedzi
+ 2
Try something like :
char str[100];
scanf ("%[^\n]%*c", str);
-- ===================
I think that fgets function is better to use for your purpose....
+ 2
Please Can you explain me what have you written in scanf function ?i dont understand.
+ 2
The expression "%[^\n]%*c"
means that all the characters entered as the input, including the spaces, until we hit the enter button are stored in the variable str
To be more specific,
[^\n] is regular expression that will exclude \n i.e in other words scanf will read all char until you hit enter button.
%*c , * is used to indicate don’t assign value to str until you hit enter or scanf encounters ‘\n’.