No wonder that with input > 10 chars buf2 gets the remainder of the input. After all you are explicitly telling the first scanf to put no more then 10 chars in buf1. What dose !0 in the 2nd scanf mean? I am getting a warning about unknown conversion type character `!' in format when I compile with -Wall. What are you trying to achieve? Have any input that is more then 10 chars discarded before the user sees the "Enter another string" message?
- To: "Linux-il" <linux-il@xxxxxxxxxxxx>
- Subject: Using fflush(stding)
- From: "Yoni Nazarathy" <ynazarty@xxxxxxxxxxxxxxxxx>
- Date: Fri, 14 Jul 2000 09:29:24 +0200
- Delivered-To: linux.org.il-linux-il@linux.org.il
- Delivery-Date: Fri Jul 14 11:23:29 2000
- Envelope-to: shaul@localhost
- Reply-To: "Yoni Nazarathy" <ynazarty@xxxxxxxxxxxxxxxxx>
Hi,Consider the following code:{puts("Enter String:");scanf("%10s",buf1);if(!fflush(stdin))perror("PROBLEM WITH FFLUSH");puts("Enter another String:");scanf("%!0s",buf2);if(!fflush(stdin))perror("PROBLEM WITH FFLUSH");printf("***%s*** ***%s***\n",buf1,buf2);}The problem is that with input that exceeds 10 chars, buf2 gets the reminder of the input.The error printed by perror is "seek error".Now, I understand that probably the terminal did not pass all of the chars to stdin thus fflush canno't flush them?Can someone comment?Yoni Nazarathy
-- Shaul Karl <shaulk@israsrv.net.il> Donate free food to the world's hungry: see http://www.thehungersite.com