C - Programming Language
This course covers the basics of programming in C. Work your way through the videos and we'll teach you everything you need to know to start your programming journey!

Getting Input From Users

Lesson 12
Author : Mike Dane
Last Updated : November, 2017


Copy// strings
char name[10];
printf("Enter your name: ");
fgets(name, 10, stdin);
printf("Hello %s! \n", name);

// ints
int age;
printf("Enter your age: ");
scanf("%d", &age);
printf("You are %d \n", age);

// chars
char grade;
printf("Enter your grade: ");
scanf("%c", &grade);
printf("You got an %c on the test \n", grade);

// doubles
double gpa;
printf("Enter your gpa: ");
scanf("%lf", &gpa);
printf("Your gpa is %f \n", gpa);