name.c (#2)

  #include <stdio.h>

  int main()
  {
     char name[31];

     printf("Name: ");
     scanf("%s", name);
     printf("Hello, %s!\n", name);
     return 0;
  }
  • In inputting the name variable, we need %s in scanf. So is in printf.
  • Note also that we do not put a & sign in front of name when doing scanf.
  • This is how we input and display strings. Try to input and display address and telephone numbers too.

 


Where to go

Chapter 2
News Page
Lesson 1 contents
Contacting Me


Roby Joehanes © 2001