Well, I had my program running perfectly, and I was quite pleased with the results. However, after I made the text file a bit big, the program just stopped working all together. (255 lines of text) so I 'suppose' it is a bandwidth problem..however 255 lines of text is like nothing, and I don't understand why it would render the program useless.
Any help on fixing the issue will be appreciated. Here is the coding:
#include<iostream>
#include<fstream>
#include<ctype.h>
using namespace std;
int main()
{
char user[255]="";
do{
int j=0,l=0;
char newuser[255]="";
cout << "Talk: ";
cin.getline (user,255);
for(int x=0;x<strlen(user);x++)
{
if ( user[x] >= 'A' && user[x] <= 'Z' )
user[x] = static_cast<char> ( user[x] + 'a' - 'A' );
if (ispunct(user[x])==0)
{
newuser[j]=user[x];
j++;
}
}
for(int x=0;x<255;x++)
user[x]=newuser[x];
char question[255][255], answer[255][255], userans[255];
int ans=0, x=0;
ifstream fromfile("questions.txt");
for(x=1;x<265;x++)
{
fromfile.getline(question[x], 255);
if(strcmp (question[x], user) == 0)
ans = x;
}
fromfile.close();
ifstream tofile("answers.txt");
for(x=1;x<265;x++)
tofile.getline(answer[x], 255);
tofile.close();
if(ans==0)
{
cout << "I am sorry, but I do not know. What would your answer be?: ";
cin.getline(userans,255);
ofstream intofile("answers.txt",ios::app);
intofile << endl << userans;
intofile.close();
ofstream tofile("questions.txt",ios::app);
tofile << endl << user;
tofile.close();
}
else
cout << "Botman says: " << answer[ans] << endl;
}while(strcmp ("let me leave", user)!= 0);
}
And the text files are below.