Advertisement
Guest User

Untitled

a guest
Jun 27th, 2019
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.99 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4.  
  5. #define BUFFER_SIZE 101
  6.  
  7. int main() {
  8. char a[101];
  9. // points to nowhere - needs initialization
  10. char *b;
  11. char c[BUFFER_SIZE];
  12. int size;
  13.  
  14. printf("\nEnter the string: ");
  15. // // Using %100 to avoid buffer overflow scanf(" %[^\n]", name);
  16. // scanf("%100s", a);
  17. gets(a);
  18. size = strlen(a);
  19. printf("\nEntered string is: %s", a);
  20. printf("\nThe length is %d", size);
  21.  
  22. // initializing b
  23. b=(char*)malloc(101*sizeof(char));
  24. printf("\nEnter another string: ");
  25. // scanf("%100s", b);
  26. gets(b);
  27. printf("\nEntered string is: %s", b);
  28. free(b);
  29.  
  30. printf("\nEnter the string with spaces e.g. Pulp Fiction: ");
  31. // fgets reads strings up to a maximum size, without stopping at whitespace
  32. // fgets does not work after scanf but works after gets
  33. fgets(c, BUFFER_SIZE, stdin);
  34. size = strlen(c);
  35. printf("\nEntered string is: %s", c);
  36. printf("\nThe length is %d", size);
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement