Hi guys. I was wondering if you could help me with this code. I am trying to open a file and read character by character. The program compiles but when I run it it aborts with an access violation while reading from the file. I made the program output the caracter it was reading and the result is like in the attached image. The file contains only characters no numbers.
ifstream indexFile;
vector<char*> vect;
string str;
char ch, text[30], *cstr;
int i = 0;
indexFile.open("C:\\test.txt");
if (indexFile.fail ())
{
cerr << "*** ERROR: Cannot open file" ;
return EXIT_FAILURE; // failure return
}
while(!indexFile.eof())
{
indexFile >> ch;
cout << ch;
while(isalpha(ch))
{
text[i] = ch;
i++;
}
text[i] = '\0';
i = 0;
vect.push_back(text);
}
indexFile.close();