Try this (lines which were changed are commented).
Code:
#include <iostream.h>
#include <fstream.h>
const int LINESIZE = 45;
int TextEqual (char target[], char lineInput[], int stringNum, int stringSize);
void ConvertLower(char target[], int size);
int main()
{
char userInput[LINESIZE];
char lineInput[LINESIZE];
ifstream inFile;
int lineCounter = 1; // holds count of what line it's on
int stringNum = 0; // holds count of string finds per line
int stringSize = 0;
inFile.open("EULA.txt");
// get string to search for and convert to lower case
// get number of characters in string
cout << "Search string: ";
cin >> userInput;
ConvertLower(userInput, 45);
//for (int counter = 0; counter < LINESIZE; counter++)
for (int counter = 0; userInput[counter]; counter++)
if ((userInput[counter] >= 97) && (userInput[counter] <= 122))
stringSize++;
cout << "The string to search for is " << userInput << endl;
cout << "The string size is " << stringSize << endl;
// print out heading
cout << "Line\tNumber" << endl;
cout << "------------" << endl;
while (inFile.peek() != EOF)
{
// get new line of data
//inFile.getline(lineInput, 50, '\n');
inFile.getline(lineInput, 45, '\n');
ConvertLower(lineInput, 45);
// prints line number and number of string finds
stringNum = TextEqual(userInput, lineInput, stringNum, stringSize);
cout << lineCounter << '\t' << stringNum << endl;
// increase the line position and set the number
// of string finds to 0
stringNum = 0;
lineCounter++;
}
inFile.close();
return 0;
}
int TextEqual(char target[], char lineInput[], int stringNum, int stringSize)
{
int numCorrect = 0;
//for (int position = 0; position < LINESIZE; position++)
for (int position = 0; lineInput[position]; position++)
{
if (lineInput[position] == target[numCorrect])
numCorrect++;
else
numCorrect = 0;
if (numCorrect == stringSize)
{
numCorrect = 0;
stringNum++;
}
}
return stringNum;
}
void ConvertLower(char target[], int size)
{
//for (int spot = 0; spot < size; spot++)
for (int spot = 0; target[spot]; spot++)
if ((target[spot] >= 65) && (target[spot] <= 90))
target[spot] = target[spot] + 32;
}
You can also use the function strlen() to get the length of a char array. To use include <cstring>