t805

String Operations

Sep 10th, 2014
202
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.62 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <string.h>
  3.  
  4. const int SIZE = 10;
  5.  
  6. int main()
  7. {
  8.     char line[SIZE] = {'\0'};
  9.  
  10.     printf("Enter string: ");
  11.     fgets(line, SIZE, stdin);
  12.  
  13.     printf("String entered was: %s.\n", line);
  14.  
  15.     printf("String length is %d.\n", strlen(line));
  16.     printf("Array's defined size is %d.\n", SIZE);
  17.     printf("Array's actual size is %d.\n\n", sizeof(line));
  18.  
  19.     printf("Removing the new line character...\n\n");
  20.     line[strlen(line) - 1] = '\0';
  21.  
  22.     printf("String entered was: %s.\n", line);
  23.     printf("String length is %d.\n", strlen(line));
  24.     printf("Array's actual size is %d.\n", sizeof(line));
  25.  
  26.     return(0);
  27. }
Advertisement
Add Comment
Please, Sign In to add comment