comparing two string arrays c++
<p>I am validating a data file for a larger program. I am at the last portion of the code and am trying to make sure two separate arrays are "equal" to each other by the strings themselves. I have included my code of the latest try. Please forgive me as I have posted the whole function.</p>

<p>Here it is:</p>

<pre><code>//
//  validateDataFile.cpp
//  P1
//
//  Created by xxxxxxx on 3/26/13.
//  Copyright (c) 2013 xxxxxxx. All rights reserved.
//

#include "p1.h"

void validateDataFile (string fileName) {
fstream file;
file.open (fileName.c_str());

if (file.is_open()) {
    unsigned int i, j, x = 0, y = 0, a;
    int flag = 0, check = 0;
    string fileData, word, strg[200];

    getline (file, fileData);

    for (i = 0; i &lt; fileData.length(); i++) {
        if ((fileData[i] == ' ') || (fileData[i] &lt; 48) || (fileData[i] &gt; 57)) {
            cout &lt;&lt; "fileData[i]: " &lt;&lt; fileData[i] &lt;&lt; endl;
            cout &lt;&lt; "Incorrect DataFile!\nFirst line should contain a positive"
            " integer and no white space" &lt;&lt; endl;
            return;
        }
    }

    int numberOfNodes = convertToInt(fileData);

    string list[numberOfNodes];

    if (numberOfNodes &lt; 0) {
        cout &lt;&lt; "Number of Nodes: " &lt;&lt; numberOfNodes &lt;&lt; endl;
        cout &lt;&lt; "Incorrect DataFile!\nFirst character should be a positive"
        "integer" &lt;&lt; endl;
        return;
    }

    getline (file, fileData);
    stringstream stream (fileData);

    while (getline (stream, word, ' ')) {
        list[x++] = word;

            for (a = 0; a &lt; numberOfNodes; a++) {
                    cout &lt;&lt; "list of nodes: " &lt;&lt; list[a] &lt;&lt; endl;   //testing only
            }
    }

    if (x != numberOfNodes) {
        cout &lt;&lt; "Incorrect DataFile!\nList of strings has more strings than"
        " the number of nodes specified in the first line." &lt;&lt; endl;
        return;
    }

    while (!file.eof()){
        getline (file, fileData);
        stringstream ss (fileData);

        while (getline (ss, word, ' ')) {


            if (convertToInt(word) &lt; 0) {
                flag = 0;
                for (i = 0; i &lt; y; i++) {
                    if (strg[i] == word) flag = 1;
                }

                if (flag == 0) strg[y++] = word;
            }
        }
    }

    for (i = 0; i &lt; y; i++) {               //&lt;- my problem starts here
        check = 0;
        for (j = 0; j &lt; x; j++) {
            if (strg[i].compare (list[j]) == 0) {
                check = 1;                  //&lt;- my problem ends here
                break;
            }
        }
    }
    if (check == 0) {
        cout &lt;&lt; "Incorrect DataFile!\nStrings listed should match Node Strings" &lt;&lt; endl;
        return;
    }
}
else {
    cout &lt;&lt; "ERROR!\n DataFile not present." &lt;&lt; endl;
    return;
}


file.close();

}
</code></pre>

<p>It compiles with no errors but doesn't do what I want it to.</p>

<p>I purposely changed my data file to create the error but for some reason it does not which tells me my comparison is incorrect.</p>

<p>Here is a small portion of my data file:</p>

<pre><code>16
Cape Birmingham Boston Chicago Dallas Detroit KansasCity LosAngeles Memphis Minneapolis Omaha Orlando Richmond SanFrancisco Seattle StLouis 
Atlanta Chicago 718
Atlanta Dallas 781
Atlanta Orlando 439
Birmingham Atlanta 146
Birmingham Detroit 723
Birmingham Richmond 678
Boston Atlanta 1099
Boston Detroit 716
Boston Memphis 1311
Chicago Atlanta 718
Chicago Boston 983
Chicago KansasCity 526
</code></pre>

<p>I purposely changed the first city to "Cape" from "Atlanta."
Can someone tell me my error and show me what needs to be done to correct it?
Thanks!</p>
