D
Darklight
is this correct or incorrect i just read the post below before posting
this: In fflush(stdin), what happens to flushed data?
this program is taken from sams teach yourself c in 21 days
/* LIST13-6.C CLEARING STDIN OF EXTRA CHARACTERS */
/* USING FFLUSH() FUNCTION */
#include<stdio.h>
int main(void)
{
int age;
char name[20];
/* PROMPT FOR USER'S AGE */
puts("Enter age: ");
scanf("%d",&age);
/* CLEAR STDIN OF ANY EXTRA CHARACTERS */
fflush(stdin);
/* PROMPT FOR USER'S NAME */
puts("Enter your name: ");
scanf("%s",name);
/* DISPLAY DATA */
printf("Your age is %d\n",age);
printf("You name is %s\n",name);
return 0;
}
my os is suse 9.1 pro
the fflush function dosn't work.
would the above program work in windows
if i replace the flush function with
void clear_kb(void)
/* CLEARS STDIN OF ANY WAITING CHARACTERS */
{
char junk[80];
fgets(junk,80,stdin);
}
the above program works
this: In fflush(stdin), what happens to flushed data?
this program is taken from sams teach yourself c in 21 days
/* LIST13-6.C CLEARING STDIN OF EXTRA CHARACTERS */
/* USING FFLUSH() FUNCTION */
#include<stdio.h>
int main(void)
{
int age;
char name[20];
/* PROMPT FOR USER'S AGE */
puts("Enter age: ");
scanf("%d",&age);
/* CLEAR STDIN OF ANY EXTRA CHARACTERS */
fflush(stdin);
/* PROMPT FOR USER'S NAME */
puts("Enter your name: ");
scanf("%s",name);
/* DISPLAY DATA */
printf("Your age is %d\n",age);
printf("You name is %s\n",name);
return 0;
}
my os is suse 9.1 pro
the fflush function dosn't work.
would the above program work in windows
if i replace the flush function with
void clear_kb(void)
/* CLEARS STDIN OF ANY WAITING CHARACTERS */
{
char junk[80];
fgets(junk,80,stdin);
}
the above program works