Clearing stdin of extra characters with extra gets_s() - C File

C examples for File:Standard Device

Description

Clearing stdin of extra characters with extra gets_s()

Demo Code

#include <stdio.h>

void clear_kb(void);

int main( void )
{
    int age;//from   ww  w . java2  s .c o m
    char name[20];

    puts("Enter your age:");
    scanf("%d", &age);

    clear_kb();

    puts("Enter your first name:");
    scanf("%s", name);

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

    return 0;
}

void clear_kb(void){
    char junk[80];
    gets_s(junk);
}

Result


Related Tutorials