Do not use scanf()
or gets()
function — use fgets()
instead. But for the above question please find the answer.
int main() {
char a[30];
scanf ("%29[^\n]%*c", name);
printf("%s\n", a);
return 0;
}
Its also highly recommended like I told in the beginning to use fgets()
instead. We clearly do not understand the weird requirement. I would have used the fgets()
to read the character.
fgets(a, size(a), stdin);
5
solved Scanf clarification in c language