Guest User

Untitled

a guest
Feb 19th, 2018
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.02 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. int main()
  5. {
  6. char fileName[200];
  7. int words;
  8. int wordcount = 0;
  9. int linecount = 0;
  10. int charcount = 0;
  11.  
  12. // Get filename
  13. printf("Enter a filename :");
  14. gets(fileName);
  15.  
  16. //Open file in read only mode
  17. FILE * fPointer;
  18. fPointer = fopen(fileName,"r");
  19.  
  20. // If file opened, continue
  21. if(fPointer)
  22. while ((words=getc(fPointer)) !=EOF)
  23. {
  24.  
  25. // Increment word count if new line or space character
  26. if ( words == 'n' || words == ' ' || words == 't')
  27. {
  28. ++wordcount;
  29. }
  30. }
  31. else
  32. {
  33. printf("No file foundn");
  34. }
  35.  
  36.  
  37. printf("wordcount is: %d",wordcount);
  38.  
  39. return 0;
  40. }
  41.  
  42. // If file opened, continue
  43. if(fPointer){
  44. while ((words=getc(fPointer)) !=EOF)
  45. {
  46.  
  47. // Increment word count if new line or space character
  48. if ( words == 'n' || words == ' ' || words == 't')
  49. {
  50. ++wordcount;
  51. }
  52.  
  53.  
  54. }
  55. wordcount++; //ADDED THIS
  56. }
Add Comment
Please, Sign In to add comment