Hello every one im doing my project for c++ class and was trying to compere 2 elements in the array to see if the length of the string that i've read from the file are the same whenever i read a row i also store the length of it in the array and now i want to compere them and return an error code if they are not the same but whenever i run a program it alway return that error for some reason
Thanks
heres the code
int wordFind(char *inFile1, char *outFile1)
{
ifstream inFile ("input.txt");
ofstream outFile ("output.txt");
struct word structArray[wordSize];
char searchMatrix[rowSize][matrixSize];
int count = 0, count2 = 0, count3 = 0;
char word[wordSize];
char matrix[matrixSize];
char temp [matrixSize];
int compResult, i;
int matrixLen;
int arrayMLen[rowSize];
int totalWords;
if (inFile.fail()){
return -1;
}
else if (outFile.fail()){
return -2;
}
inFile >> temp;
compResult = strncmp(temp, "***", 3);
while (compResult != 0)
{
structArray[count].wordLen = strlen (temp);
structArray[count].wordPtr = new char [structArray[count].wordLen + 1];
strcpy(structArray[count].wordPtr, temp);
count++;
inFile >> temp;
compResult = strncmp(temp, "***", 3);
}
totalWords = count;
if (count > wordSize){
return -6;
}
compResult = strncmp(matrix, "***", 3);
inFile >> matrix;
while (compResult != 0)
{
strcpy(searchMatrix[count2], matrix);
[B]matrixLen = strlen (matrix);
arrayMLen[count2] = matrixLen;[/B]
count2++;
inFile >> matrix;
compResult = strncmp(matrix, "***", 3);
}
if (count2 > rowSize){
return -7;
}
for (i = 0; i <= rowSize ; i++){
[B] if (arrayMLen[0] != arrayMLen[i + 1])
return -5;[/B] }
for ( i = 0; i <= wordSize - 1; i++){
for (int j = 0; j <= rowSize; j++){
char* result = strstr(searchMatrix[j], structArray[i].wordPtr);
if (result != NULL){
outFile << structArray[i].wordPtr << " horizRight " << endl;
}
}
}
inFile.close();
outFile.close();
return totalWords;
}