grade.c

  #include <stdio.h>

  int main()
  {
     char name[31];
     char grade;

     printf("Name : ");
     scanf("%s", name);
     printf("Grade: ");
     scanf("%c", &grade);
     printf("Hello, %s, You got an %c!\n", name, grade);
     return 0;
  }
  • In this program, we also input a char variable called grade. Notice the difference on declaration. There is no square brackets.
  • The variable grade can only hold 1 character, whereas the variable name name can hold 31 characters.
  • Thus, variable of type char typically useful in specifying grade letters.
  • Note the %c in both scanf and printf. Note also the & sign when doing scanf.

 


Where to go

Chapter 2
News Page
Lesson 1 contents
Contacting Me


Roby Joehanes © 2001