Advertisement
thenewboston

C Programming Tutorial - 46 - Problems with String Lengths

Aug 22nd, 2014
442
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.50 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 movie [20];
  9.     char * pMovie = movie; //no & is needed
  10.  
  11.     // this array only has space for 20 items
  12.     // if we store more than 20, some data can get overwritten
  13.     // fgets limits the input to a certain amount
  14.     // if the user enters more, then it will only get the first 20
  15.  
  16.     fgets(pMovie, 20, stdin); //stdin means input from keyboard, not file
  17.     puts(pMovie);
  18.  
  19.     return 0;
  20. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement