Reputation: 5
I am going through one small code where I need to take whole line as input through scanf function, and I think there is one format specifier "[^\n%*c]" can someone please tell me syntax for it and how it works?
Upvotes: 0
Views: 399
Reputation: 31296
The best way is probably to use fgets
.
char str[20];
fgets(str, 20, stdin);
printf("%s", str);
No reason to use scanf
here. Just remember that fgets
also puts the newline character in the buffer. It can be removed like this:
str[strcspn(str, "\n")] = 0;
Upvotes: 1
Reputation: 523
#include <stdio.h>
int main()
{
char str[20];
scanf("%19[^\n]%*c", str);
printf("%s\n", str);
return 0;
}
Upvotes: 0