Hello people.... I have a question, why we use scanf(" %[^\n]) and another one ,scanf("%[^\n]%*c) | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Hello people.... I have a question, why we use scanf(" %[^\n]) and another one ,scanf("%[^\n]%*c)

1st Oct 2023, 9:00 PM
Hiriharan V M EEE
Hiriharan V M EEE - avatar
2 Answers
+ 2
Hiriharan V M EEE If I understand this syntax correctly. Then in the first case the code would be taking a characters on a line up until the newline. The second case wouldbe similar except then the last character would also be consumed, however it would not be assigned. So I would expect the second scanf to read all the characters up until the newline, then consume and discard the newline to clear the input buffer.
2nd Oct 2023, 7:14 AM
The Darkness
The Darkness - avatar
+ 1
Yeah ur near to the answer but it's not clear ... The Darkness
2nd Oct 2023, 8:07 AM
Hiriharan V M EEE
Hiriharan V M EEE - avatar