Advertisement
thenewboston

C Programming Tutorial - 11 - Getting Input with scanf

Aug 22nd, 2014
663
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.57 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. int main()
  5. {
  6.     char firstName[20];
  7.     char crush[20];
  8.     int numberOfBabies;
  9.  
  10.     printf("What is your name? \n");
  11.     scanf("%s", firstName);
  12.  
  13.     printf("Who are you going to marry? \n");
  14.     //scanf() stops when it sees a space, so no last names
  15.     scanf("%s", crush);
  16.  
  17.     printf("How many kids will you have? \n");
  18.     //ampersand needed for everything but arrays
  19.     scanf("%d", &numberOfBabies);
  20.  
  21.     printf("%s and %s are in love and will have %d babies", firstName, crush, numberOfBabies);
  22.  
  23.     return 0;
  24. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement