I wrote this string palindrome program that reads input from a text file. All the syntax are correct but I have an error I couldn't understand. Any help is appreciated, thanks!!!
First, this is the error message:
Error 1 error LNK2001: unresolved external symbol "char * newToCheck"
(?newToCheck@@3PADA)
And this...
Error 2 error LNK1120: 1 unresolved externals
This is my code so far:
#include <iostream>
#include <fstream>
using namespace std;
const int strSize = 0xFF;
ifstream infile;
char checkPhrase[strSize], origPhrase[strSize], newToCheck[];
int cleanup (char*, int), newCount;
bool palindrome (char*, int, int);
int main()
{
infile.open ("C:\\Documents and Settings\\student\\Desktop\\PalindromeData.rbh");
if (!infile)
{
cout << "File not found. Check your directory and/or file and try again.\n\nEnter any key to exit..." << endl;
cin.get();
exit(1);
}
while (!infile.eof())
{
infile.getline(origPhrase, sizeof(checkPhrase));
for (int i = 0; i < strSize; i++)
checkPhrase[i] = origPhrase[i];
newCount = cleanup (checkPhrase, strlen(checkPhrase));
newToCheck [newCount];
for (int n = 0; n < newCount; n++)
newToCheck[n] = checkPhrase[n];
if (palindrome (newToCheck, 0 , newCount - 1))
cout << "The phrase " << origPhrase << " is a Palindrome\r\n.";
else
cout << "The phrase " << origPhrase << " is not a Palindrome\r\n.";
}
infile.close();
cin.get();
return 0;
}
int cleanup (char* phrase, int size)
{
int currentChar = 0;
for(int i = 0; i < size; i++)
{
if(((int)phrase[i] >= 48 && (int)phrase[i] <= 57) || ((int)phrase[i] >= 65 && (int)phrase[i] <= 90) || ((int)phrase[i] >= 97 && (int)phrase[i] <= 122))
{
phrase[currentChar] = tolower(phrase[i]);
currentChar++;
}
}
return currentChar;
}
bool palindrome (char* phrase, int start, int end)
{
if(phrase[start] == phrase[end])
{
if(start == end || start + 1 == end)
{
return true;
}
else
{
return palindrome(phrase, start + 1, end - 1);
}
}
else
{
return false;
}
}