Counting vowels form a file

I am working on a program that will acess a file, and load the data into a string, using the string, compare each cha to a refferance to see if it is a vowel, @ the end show how many vowels, and how many for each. This is what I have now:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#include <iostream>
#include <string>
#include <fstream>
#include <stdio.h>
#include <ctype.h>

using namespace std;

int main()
{
    char curLetter, v[500];
	int a, i, len, vA, vE, vI, vO, vU, vY, totV;

	a=0, vA=0, vE=0, vI=0, vO=0, vU=0, vY=0, totV=0;

	len=strlen(v);

	ifstream infile;
	infile.open("c:\\1.txt");

	if (!infile)
		cout << "NO INPUT FILE!!!" << endl;
	
	while ((v[a++]=infile.get()) != EOF)a;

	{
		for (i=0; i < len; ++i)
		{
			curLetter = (toupper(v[i]));
			
			if (curLetter = 'A')
			{
				vA++;
				totV++;
			}
			else if (curLetter = 'E')
			{
				vE++;
				totV++;
			}
			else if (curLetter = 'I')
			{
				vI++;
				totV++;
			}
			else if (curLetter = 'O')
			{
				vO++;
				totV++;
			}
			else if (curLetter = 'U')
			{	vU++;
				totV++;
			}
			else if (curLetter = 'Y')
			{
				vY++;
				totV++;
			}
		}
	}

	cout <<	"Total Vowels: " << totV;
	cout <<	"\nTotal A: " << vA;
	cout <<	"\nTotal E: " << vE;
	cout <<	"\nTotal I: " << vI;
	cout <<	"\nTotal O: " << vO;
	cout <<	"\nTotal U: " << vU;
	cout <<	"\nTotal Y: " << vY << endl;

	//infile.close();
	
	return 0;
    
}




My OUTPUT looks like this:


Total Vowels: 523
Total A: 523
Total E: 0
Total I: 0
Total O: 0
Total U: 0
Total Y: 0
Press any key to continue . . .

HELP PLEASE!!!!!!!
Last edited on
well, you never seem to use <string>, although, i wouldn't really use a string anyway, i think a more streamlined version of this would be to use a loop to read in individual characters at a time from the file, compare it right then, and increment what variables you need to, then move to the next char from the file until you get EOF., then print what you need. there isn't a reason i can see to store all of the characters from the file when you could cut back on memory and just analyze a char at a time. maybe that would work?

ps, i'm also not sure this is such a great idea:
while ((v[a++]=infile.get()) != EOF)a;
i don't think i would try and increment a variable in there, and i'm not sure what that stray "a;" is at the end before the opening brace of the loop
thats the thing, i dont think i am even accessing the file right, as to the
while ((v[a++]=infile.get()) != EOF)a;
I was told I need to use a while loop, and that while loop is what reads in the cha. I am still lost in the sauce.
 
if (curLetter = 'A')


= is the assignment operator, not the comparison operator.
hence this check is always true.
Topic archived. No new replies allowed.