0% found this document useful (0 votes)
20 views1 page

#Include #Include

This C program counts the number of lines in a text file. It opens the file, defines a function that iterates through each character and increments a counter variable whenever a new line is encountered, and calls this function to count the lines. It then prints out the final line count.

Uploaded by

kalanithi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
20 views1 page

#Include #Include

This C program counts the number of lines in a text file. It opens the file, defines a function that iterates through each character and increments a counter variable whenever a new line is encountered, and calls this function to count the lines. It then prints out the final line count.

Uploaded by

kalanithi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 1

#include <stdlib.

h>
#include <stdio.h>
int countWords(FILE *f){
int count = 0;
char ch;
while ((ch = fgetc(f)) != EOF){
if (ch == '\n')
count++;
}
return count;
}
int main(void){
int wordCount = 0;
FILE *rFile = fopen("american0.txt", "r");
wordCount += countWords(rFile);
printf("%d", wordCount);
return 0;
}

You might also like