How can I fix this debug \"error\"? \"error C2065: \'list\' : undeclared identif
ID: 3632098 • Letter: H
Question
How can I fix this debug "error"?
"error C2065: 'list' : undeclared identifier"
Program is here:
// : Defines the entry point for the console application.
//
#include<iostream>
#include<fstream>
#include<cctype>
using namespace std;
void initialize(int& lc, int list[]);
void copyText(ifstream& intext, ofstream& outtext, char& ch, int list[]);
void characterCount(char ch, int list[]);
void writeTotal(ofstream& outtext, int lc, int list[]);
int main()
{
//Step 1: Declare Variables
int lineCount;
int letterCount[26];
char ch;
ifstream infile;
ofstream outfile;
infile.open("textin.txt");
if (!infile)
{
cout << "Cannot open the input file."
<< endl;
}
outfile.open("textout.out");
initialize(lineCount, letterCount);
infile.get(ch);
while (infile)
{
copyText(infile, outfile, ch, letterCount);
lineCount++;
infile.get(ch);
}
writeTotal(outfile, lineCount, letterCount);
infile.close();
outfile.close();
system("pause");
return 0;
}
void initialize(int& lc, int list[])
{
int j;
lc = 0;
for (j = 0; j < 26; j++)
list[j] = 0;
} // end initialize
void copyText(ifstream& intext, ofstream& outtext, char& ch,
int list[])
{
while (ch != ' ')
{
outtext << ch;
characterCount (ch, list);
intext.get(ch);
}
outtext << ch;
}
void characterCount(char ch, int lst[])
{
int index;
ch = toupper(ch);
index = static_cast<int>(ch) - static_cast<int>('A');
if (0 <= index && index < 26)
list[index]++;
} // end characterCount
void writeTotal(ofstream& outtext, int lc, int list[])
{
int index;
outtext << endl << endl;
outtext << "The number of lines = " << lc << endl;
for (index = 0; index < 26; index++)
outtext<< static_cast<char>(index + static_cast<int>('A'))
<<" count = " << list[index] << endl;
}// end writeTotal
Explanation / Answer
please rate - thanks
would you believe you spelled list wrong--I ran it and I believe it works great
// : Defines the entry point for the console application.
//
#include<iostream>
#include<fstream>
#include<cctype>
using namespace std;
void initialize(int& lc, int list[]);
void copyText(ifstream& intext, ofstream& outtext, char& ch, int list[]);
void characterCount(char ch, int list[]);
void writeTotal(ofstream& outtext, int lc, int list[]);
int main()
{
//Step 1: Declare Variables
int lineCount;
int letterCount[26];
char ch;
ifstream infile;
ofstream outfile;
infile.open("textin.txt");
if (!infile)
{
cout << "Cannot open the input file."
<< endl;
}
outfile.open("textout.out");
initialize(lineCount, letterCount);
infile.get(ch);
while (infile)
{
copyText(infile, outfile, ch, letterCount);
lineCount++;
infile.get(ch);
}
writeTotal(outfile, lineCount, letterCount);
infile.close();
outfile.close();
system("pause");
return 0;
}
void initialize(int& lc, int list[])
{
int j;
lc = 0;
for (j = 0; j < 26; j++)
list[j] = 0;
} // end initialize
void copyText(ifstream& intext, ofstream& outtext, char& ch,
int list[])
{
while (ch != ' ')
{
outtext << ch;
characterCount (ch, list);
intext.get(ch);
}
outtext << ch;
}
void characterCount(char ch, int list[])
{
int index;
ch = toupper(ch);
index = static_cast<int>(ch) - static_cast<int>('A');
if (0 <= index && index < 26)
list[index]++;
} // end characterCount
void writeTotal(ofstream& outtext, int lc, int list[])
{
int index;
outtext << endl << endl;
outtext << "The number of lines = " << lc << endl;
for (index = 0; index < 26; index++)
outtext<< static_cast<char>(index + static_cast<int>('A'))
<<" count = " << list[index] << endl;
}// end writeTotal
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.