We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
scanf("%c", &ch); reads a single character.
scanf("%s", s); reads a string until a space is encountered, leaving the newline character in the buffer.
getchar(); consumes the newline character left in the buffer after reading the string.
scanf("%[^\n]%*c", sen); then reads the entire sentence correctly.
Playing With Characters
You are viewing a single comment's thread. Return to all comments →
scanf("%c", &ch); reads a single character. scanf("%s", s); reads a string until a space is encountered, leaving the newline character in the buffer. getchar(); consumes the newline character left in the buffer after reading the string. scanf("%[^\n]%*c", sen); then reads the entire sentence correctly.
char ch; scanf("%c",&ch); printf("%c\n",ch);