Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* Write a program that calls from a list of names, */
- /* and print counts how many times each name appears. */
- /* The amount of file names not known in advance. */
- /* We can assume that each name appears on a separate line. */
- #include<stdio.h>
- #include<stdlib.h>
- // function for count all of the words in the program
- int countWord(FILE *file)
- {
- int count = 0;
- char ch;
- // loop for counting words that shared by space
- while ((ch = fgetc(file)) != EOF)
- {
- if (ch == '\n')
- count++; // count all of the words in the program
- }
- return count;
- }
- // main() must return an integer
- void main() //settings function main ()
- {
- int wordCount = 0;
- // open file it read-only mode
- FILE *file = fopen("d:\\names.txt", "r");
- //save the count words in the program in variable wordCount
- wordCount += countWord(file);
- printf("We have %d words in the file\n", wordCount); // printg a counted words in file
- }
Add Comment
Please, Sign In to add comment