Hello,
I'm developing an application that reads a text file, and then replaces what's in the text file with an array (alphabet) It all works ok until I try and change the position of the inputted character and it returns:
Segmentation fault: 11 It's really confusing!
Here is my code:
#include <iostream>
#include <fstream>
#include <vector>
using namespace std;
bool file_exists(string theFile)
{
ifstream file(theFile.c_str());
if(file)
{
return true;
}else{
return false;
}
}
int main()
{
string alphabet[26] = {"a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z" };
if(file_exists("helloworld.txt"))
{
string str;
string words[1000];
int* pointer;
ifstream file("helloworld.txt");
for(int i=0; !file.eof(); i++)
{
words[i] = file.get();
for(int o=0; (o < 26); o++)
{
if(words[i] == alphabet[o])
{
words[i] = alphabet[o + 9];
cout << words[i];
}else{
}
}
}
}else{
cout << "The file does not exist";
}
return EXIT_SUCCESS;
}
Any ideas? Thanks =)