Hey, everyone! I've got small problem in this code! I cannot find a mistake in this code. I was playing many times by changing functions and values, but something wrong. I'm beginer in C++, but I would like to be professional. I never ask for codes, only help for explaining. Thank you!!!
Compiler shows error:(59)error C2181: illegal else without matching if //-???
(65) error C1075: end of file found before than left brace... //-???
//Specification: Count the letter is a Text file
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
const char FileName[] = "c:\\TestCount.txt";
int main()
{
string lineBuffer;
ifstream inMyStream (FileName); //open my file stream
if (inMyStream.is_open()){
//create an array to hold the letter counts
int upperCaseCount[26] = {0};
int lowerCaseCount[26] = {0};
//read the text file
while (!inMyStream.eof()){
//get a line of text
getline (inMyStream, lineBuffer);
//read through each letter in the lineBuffer
char oneLetter;
for( int n=0; n < lineBuffer.length(); ++n ){
oneLetter = char( lineBuffer[n] ); //get a letter
if (oneLetter >= 'A' && oneLetter <='Z'){ //decide if it is a capital letter
upperCaseCount[int(oneLetter)- 65]++; //make the index match the count array
}
if (oneLetter >= 'a' && oneLetter <='z'){ //decide if it is a lower case letter
upperCaseCount[int(oneLetter)- 97]++; //make the index match the count array
}
}//end while
inMyStream.close(); //close the file stream
//display the counts
for (int i = 0; i < 26; i++)
cout << char(i + 65) << "\t\t" << upperCaseCount[i] << endl;
for (int i = 0; i < 26; i++)
cout << char(i + 97) << "\t\t" << lowerCaseCount[i] << endl;
}
else
cout << "File Error: Open Failed";
return 0;
}