Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #define BUFFER_SIZE 101
- int main() {
- char a[101];
- // points to nowhere - needs initialization
- char *b;
- char c[BUFFER_SIZE];
- int size;
- printf("\nEnter the string: ");
- // // Using %100 to avoid buffer overflow scanf(" %[^\n]", name);
- // scanf("%100s", a);
- gets(a);
- size = strlen(a);
- printf("\nEntered string is: %s", a);
- printf("\nThe length is %d", size);
- // initializing b
- b=(char*)malloc(101*sizeof(char));
- printf("\nEnter another string: ");
- // scanf("%100s", b);
- gets(b);
- printf("\nEntered string is: %s", b);
- free(b);
- printf("\nEnter the string with spaces e.g. Pulp Fiction: ");
- // fgets reads strings up to a maximum size, without stopping at whitespace
- // fgets does not work after scanf but works after gets
- fgets(c, BUFFER_SIZE, stdin);
- size = strlen(c);
- printf("\nEntered string is: %s", c);
- printf("\nThe length is %d", size);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement