How to get keyboard input in C language

How to get keyboard input in C language

You can use the scanf function, and the corresponding header file is stdio.h

/*
Example: take the input from keyboard in C language
*/

#include <stdio.h>
#include <stdlib.h>

int main(int argc, char const *argv[]) {

    char name[20];
    int age;

    printf("Input a name : ");
    scanf("%[^\n]s",name);

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

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

    return 0;

}
Sour‮w:ec‬ww.lautturi.com

output:

Input a name : lau tturi 
Input the age: 5
The name is: lau tturi 
The age is: 5
Created Time:2017-08-29 09:08:16  Author:lautturi