Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- int main()
- {
- char fileName[200];
- int words;
- int wordcount = 0;
- int linecount = 0;
- int charcount = 0;
- // Get filename
- printf("Enter a filename :");
- gets(fileName);
- //Open file in read only mode
- FILE * fPointer;
- fPointer = fopen(fileName,"r");
- // If file opened, continue
- if(fPointer)
- while ((words=getc(fPointer)) !=EOF)
- {
- // Increment word count if new line or space character
- if ( words == 'n' || words == ' ' || words == 't')
- {
- ++wordcount;
- }
- }
- else
- {
- printf("No file foundn");
- }
- printf("wordcount is: %d",wordcount);
- return 0;
- }
- // If file opened, continue
- if(fPointer){
- while ((words=getc(fPointer)) !=EOF)
- {
- // Increment word count if new line or space character
- if ( words == 'n' || words == ' ' || words == 't')
- {
- ++wordcount;
- }
- }
- wordcount++; //ADDED THIS
- }
Add Comment
Please, Sign In to add comment