Hi all,
The easiest way is to add the line
scanf("%*c");
This will take a way the end of line in the buffer.
Hi all,
The easiest way is to add the line
scanf("%*c");
This will take a way the end of line in the buffer.
I'm not a Pro Programmer, but then I could suggest you to use a single line and get rid off your probrlem!!!
fflush(stdin) flushes the standard input stream... fflush() function is defined in <conio.h> and is supplied with all the compilers I've used!!Code:#include <stdio.h> #include <conio.h> #include <ctype.h> #include <process.h> #define pause getch() #define clear clrscr() void main(void) { char UserName[25]; char UserPhone[10]; char UserChoice = ' '; clear; printf("\nName: "); gets(UserName); printf("\nPhone: "); gets(UserPhone); printf("\nContinue [Y/N] ? : "); scanf("%c", &UserChoice); fflush(stdin); // flush the standard input stream after scanf if(toupper(UserChoice) == 'Y') main(); printf("\nPress any key to exit..."); pause; exit(0); }
No, it results in undefined behaviour. fflush() is only defined for output and update streams.Originally Posted by musaid
No, it is declared in <stdio.h>Originally Posted by musaid
That is probably true, since it is part of the C standard library.Originally Posted by musaid
Look up a C++ Reference and learn How To Ask Questions The Smart WayOriginally Posted by Bjarne Stroustrup (2000-10-14)
what this line actually did.i put it and yes the problem was solved.can you explian it a bit.
also when i put this line instead of scanf
then also the same problem persisted.why?does getchar also leaves the any character in the buffer?Code:printf("\nContinue [Y/N] ? : "); UserChoice=getchar();
Thank You
Last edited by BEN10; 04-04-2009 at 08:49 AM.