I have coded the following codes,but there was a problem
char p[20];
int n;
errno = 0;
n = scanf("%[^\n]",p);
if (1 == n)
{
printf("%s\n",p);
scanf("%[^\n]",p); /*no waiting for input*/
printf("%s\n",p);
}
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
This says scan every character except
\nie ENTER key. So it allows you to enter a string and you would have pressed ENTER. This ENTER character is still instdinbuffer which will terminate your nextscanfstatementand hence it seems to you that it dint execute!
scanf, reads first from the buffer, if it doesn’t find sufficient data there, then waits for your input.Feed the ENTER you entered first to some function like
getchar(). ie add agetchar()before your secondscanfand now your secondscanfwill accept input fromstdinSomething like