Date: Tue, 17 Nov 1998 11:06:31 +0200 (IST) From: Eli Zaretskii X-Sender: eliz AT is To: "G.B.Rotman" cc: djgpp AT delorie DOT com Subject: Re: scanf/gets bug? In-Reply-To: <36506D06.965F8EC6@stud.biol.ruu.nl> Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Reply-To: djgpp AT delorie DOT com On Mon, 16 Nov 1998, G.B.Rotman wrote: > This simple test program doesn't even work for me, > when I run it scanf waits until two integers are > given and then skips gets, I assume because of the > newline which is still left in the buffer. No, it works like it should, but \n in the format strings causes `scanf' to read as many newlines and whitespace characters as possible, so it waits for you to type any non-whitespace character and only returns after it sees that. The second number is actually consumed by `gets' (try printing the `string' variable and you will see it), and the only undesirable effect is that the prompt "give input for gets()" is not printed where you want it. Your original program didn't include this second prompt, so this little subtlety didn't matter then. Here's a slightly modified program that will do what you want: #include int main() { int a; char string[25]; puts("\ngive input for scanf()\n"); scanf("%d", &a); puts("give input for gets()\n"); scanf("\n"); gets(string); puts(string); puts("end"); }