statistical analysis of a file of char

I having problem with my program, it is entering a if condition when I do not want it to. Below is my code. so far it's just supposed to count the occurences of each char.

#include <fstream>
#include <iostream>
#include <vector>
#include <string>
using namespace std;

void processFile(string str);

struct dataNode
{
    char charac;
    unsigned int count;
};

int main()
{
    string dataIn;
    string statString;
    int numOfUniqueChar = 0;
    ifstream inFile;//input file
    vector <dataNode> data(1);
    cout << "input file to do simple statistical analysis: ";
    cin >> dataIn;
    cout << "a string with no duplicates: ";
    cin >> statString;
    string dataString;

    inFile.open(dataIn.c_str());
    if(inFile.fail())
    {
        cout << "Input file opening failed.\n";
        exit(1);
    }
   
    while(!inFile.eof())
        getline(inFile, dataString);
   
    cout << dataString << endl;
   
    char toBeComp = dataString[0];
    for(int i = 0; i < dataString.length(); i++)
    {
        if(numOfUniqueChar == 0)
        {
            numOfUniqueChar++;
            dataNode temp;
            temp.charac = toBeComp;
            temp.count = 1;
            data[0] = temp;
        }
        else
        {
            bool foundSame = false;
            for( int j = 0; j < numOfUniqueChar; j++)
            {
                bool sameChar = (data[j].charac == toBeComp);
                if(sameChar);//<<<<<<<<<<<<<<<<<<why is it entering this loop when my input file is a string "abc"
                {
                    data[j].count++;
                    foundSame = true;
                }
                if(foundSame)
                break;
            }
            if(!foundSame)
            {
                dataNode temp2;
                temp2.charac = toBeComp;
                temp2.count = 1;
                data[numOfUniqueChar] = temp2;
                numOfUniqueChar++;
            }  
        }
        toBeComp = dataString[i + 1];
    }
   
    for(int i = 0; i < numOfUniqueChar; i++)
    {
        cout << data[i].charac << " " << data[i].count << endl;
    }    

    return 1;
}
kynphanAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

AxterCommented:
Because you  have a simicoln at the end of the if condition line
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
AxterCommented:
if(sameChar);

The above line has a semicoln.
Remove the simicoln and make it the following:
                if(sameChar)
                {
                    data[j].count++;
                    foundSame = true;
                }
0
Sys_ProgCommented:
Hi kynphan,
>  if(sameChar);//<<<<<<<<<<<<<<<<<<why is it entering this loop when my

The semilcolon at the end of if ends your "if" statement
hence the next statement is always executed
It should be
 if(sameChar)

Cheers!
0
kynphanAuthor Commented:
wow, i feel stupid! i must be thinking about something else while i was doing this, thanks guys.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C++

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.