๐Ÿ‡ฎ๐Ÿ‡ณ India's Free Coding Tutorial โ€” Learn C, PHP, MySQL, Python, Java About ยท Contact
Advertisement

Input with scanf()

C Language Variables & Data Types ๐Ÿ“… Mar 2026 โฑ 5 min read ๐Ÿ†“ Free

User Input with scanf()

c
#include <stdio.h>
int main() {
    int age;
    float salary;
    char name[50];
    
    printf("Enter your name: ");
    scanf("%s", name);
    
    printf("Enter age: ");
    scanf("%d", &age);
    
    printf("Enter salary: ");
    scanf("%f", &salary);
    
    printf("Name: %s
", name);
    printf("Age: %d, Salary: %.2f
", age, salary);
    return 0;
}
Important! scanf reads only one word (stops at space). Use fgets() for full line with spaces: fgets(name, 50, stdin);

Multiple Inputs

c
int a, b, c;
printf("Enter 3 numbers: ");
scanf("%d %d %d", &a, &b, &c);
printf("Sum = %d
", a+b+c);
Advertisement
โ† Back to C Language Index