Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #define IN 1
- #define OUT 0
- int main()
- {
- while (1)
- {
- FILE *fptr1;
- char filename[100];
- printf("Enter the filename to open for reading n");
- scanf("%s", filename);
- fptr1 = fopen(filename, "r");
- int c, nl, nw, nc, state; // These variables aren't being reset.
- while ((c = fgetc(fptr1)) != EOF)
- {
- ++nc;
- if (c == 'n') ++nl;
- if (c == 't' || c == 'n' || c == ' ') state = OUT;
- else if (state == OUT)
- {
- state = IN;
- ++nw;
- }
- };
- printf("Lines: %d Words: %d Characters: %dn", nl, nw, nc);
- }
- return 0;
- }
- Enter the filename to open for reading
- data.txt
- Lines: 6 Words: 15 Characters: 81
- Enter the filename to open for reading
- data.txt
- Lines: 12 Words: 30 Characters: 162
- Enter the filename to open for reading
Add Comment
Please, Sign In to add comment