Question of Code Blocks

E

E_Dn

Guest
Hi....
I'm code blocks user.
Actually I'm learning it.

Then.. I'm in trouble in using fflush().

It doesn't work.

In C programing book," fflush(stdin); " deletes buffer...

So I wrote the code like this.

Code:
#include<stdio.h>
int main(void)
{
int age;
char name[20];

printf("Write age : ");
scanf("%d", &age);

fflush(stdin);

printf("Write name : ");
fgets(name, sizeof(name), stdin);

printf("%d \n", age);
printf("%s \n", name);

return 0;
}

Result...

Write age : 19
Write name : 19 //this is automatically Written...

...End...
 


that no problem..

you can try delete """printf("%s \n", name)""", recompile and run it...
and then, I thought you should see ...like this
"""
Write age: 19
Write name: 19
"""
your "print info", deceive you...
the "fflush()" was able to work...

p.s:sorry, im not good at English...hope you can understand...
 

Members online


Top