Guest User

Untitled

a guest
Nov 20th, 2017
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.81 KB | None | 0 0
  1. #include <stdio.h>
  2. #define IN 1
  3. #define OUT 0
  4.  
  5. int main()
  6. {
  7. while (1)
  8. {
  9. FILE *fptr1;
  10. char filename[100];
  11. printf("Enter the filename to open for reading n");
  12. scanf("%s", filename);
  13. fptr1 = fopen(filename, "r");
  14.  
  15. int c, nl, nw, nc, state; // These variables aren't being reset.
  16.  
  17. while ((c = fgetc(fptr1)) != EOF)
  18. {
  19. ++nc;
  20. if (c == 'n') ++nl;
  21. if (c == 't' || c == 'n' || c == ' ') state = OUT;
  22. else if (state == OUT)
  23. {
  24. state = IN;
  25. ++nw;
  26. }
  27. };
  28. printf("Lines: %d Words: %d Characters: %dn", nl, nw, nc);
  29. }
  30. return 0;
  31. }
  32.  
  33. Enter the filename to open for reading
  34. data.txt
  35. Lines: 6 Words: 15 Characters: 81
  36. Enter the filename to open for reading
  37. data.txt
  38. Lines: 12 Words: 30 Characters: 162
  39. Enter the filename to open for reading
Add Comment
Please, Sign In to add comment