[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Using fflush(stding)



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?


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