Counting characters from a file

Hi,

I have to write a program that determines the frequency of a letter specified by the user in an input file. I am kind of stuck. I know I have to write a user defined program, to count the total number of letters, but I'm just not sure how to do that for a file. This is what I have so far, if anyone could point me in the right direction that would be great.
Thanks

#include <stdio.h>

int count(FILE *filePtr, int *allCount, char letter);
void totalLetters(FILE *filePtr, int *count, int *allCount, char letter);
int main()
{

int allCount;
char letter;
FILE *inFilePtr;
inFilePtr = fopen("file1.txt", "r");

count(inFilePtr, allCount, letter);
printf("There are %d characters in the file\n", count);


printf("Enter a letter:");
scanf("%c", &letter);

return 0;
}// end main function

int count(FILE *filePtr, int *allCount, char letter) // function definition
{
int allCount=0;
FILE *inFilePtr;
while( !feof(inFilePtr)){ //I'm not sure if this is how you count the number
allCount++ ; of letters

return allCount;
}
}
You can use seekg() and tellg() to get the size of an open file
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
int main()
{
	ifstream ifs("read.txt");


	if (!ifs) {
		cout << "can not open file" << endl;
		exit(EXIT_FAILURE);
	}

	char c;
	int count = 0;

	while (ifs >> c)
		count++;

	cout <<"count:" << count << endl;

	return 0;
}
Topic archived. No new replies allowed.