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

Re: Using fflush(stding)



In the Previous message about fflush() there is a typo in the second scanf.
The code:
scanf("%!0s",buf2);
should be:
scanf("%10s",buf2);
 
        Thnkx,
        Yoni
 
-----Original Message-----
From: Yoni Nazarathy <ynazarty@study.haifa.ac.il>
To: Linux-il <linux-il@linux.org.il>
Date: יום שישי 14 יולי 2000 09:55
Subject: Using fflush(stding)

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