Course Hive
Search

Welcome

Sign in or create your account

Continue with Google
or
Learn how to enter user input in C! ⌨️
Play lesson

C tutorial for beginners ⚙️ - Learn how to enter user input in C! ⌨️

4.0 (0)
13 learners

What you'll learn

This course includes

  • 6.5 hours of video
  • Certificate of completion
  • Access on mobile and TV

Summary

Keywords

Full Transcript

#coding #programming #cprogramming 00:00:00 VSCode setup 00:01:55 declaring variables 00:02:57 undefined behavior 00:06:31 scanf 00:09:47 input buffer 00:10:47 scanf w/ strings 00:12:16 fgets 00:13:20 getchar() 00:14:05 removing \n from a string int age = 0; float gpa = 0.0f; char grade = '\0'; char name[50] = ""; printf("Enter your age: "); scanf("%d", &age); printf("Enter your gpa: "); scanf("%f", &gpa); printf("Enter your grade: "); scanf(" %c", &grade); // The space before %c is necessary to consume any leftover \n. getchar(); // clears \n from input buffer printf("Enter your full name: "); fgets(name, sizeof(name), stdin); name[strlen(name) - 1] = '\0'; //changes last char from \n to \0 printf("%s\n", name); printf("%d\n", age); printf("%.2f\n", gpa); printf("%c\n", grade); return 0;

Course Hive

Continue this lesson in the app

Install CourseHive on Android or iOS to keep learning while you move.

Related Courses

FAQs

Course Hive
Download CourseHive
Keep learning anywhere