Question of Code Blocks

Discussion in 'General Linux' started by E_Dn, Mar 30, 2013.

  1. E_Dn

    E_Dn New Member

    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    0
    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...
  2. littlekey_yuki

    littlekey_yuki New Member

    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    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...

Share This Page