thenewboston

C Programming Tutorial - 35 - puts and gets

Aug 22nd, 2014
466
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.58 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <ctype.h>
  4. #include <string.h>
  5.  
  6. int main()
  7. {
  8.     char catsName[50];
  9.     char catsFood[25];
  10.     char sentence[75] = "";
  11.  
  12.     // puts is awesome way print strings to screen
  13.     // gets is great for getting string from user
  14.     // unlike scanf(), you can have spaces
  15.     puts("Whats that dumb cats name? ");
  16.     gets(catsName);
  17.  
  18.     puts("What does he eat? ");
  19.     gets(catsFood);
  20.  
  21.     strcat(sentence, catsName);
  22.     strcat(sentence, " loves to eat ");
  23.     strcat(sentence, catsFood);
  24.  
  25.     puts(sentence);
  26.  
  27.     return 0;
  28. }
Advertisement
Add Comment
Please, Sign In to add comment