Hey everyone,,,
I am new to c++ and to reading from files especially... I wrote a code where I am filling an array of strings with strings from a file and there is an error that happen during the run of the program, please have a look at the reading and an overall look at everything and tell me where I went wrong
please reply cause this is sort of a last minute error and I have to submit this code for tomorrow,,,, HELP!!
THANKS
#include<iostream>
#include<string>
#include<fstream>
using namespace std;
int main ()
{
int N, rings;//N is the test cases
string unlockingWord, secretWord;
char *fileName = new char;
ifstream inFile;
cout<<"\nEnter the number of test cases : "; cin>>N;
cout<<"_____________________________________\n";
for (int i=0; i<N; i++)
{
cout<<"\nEnter the number of rings : ";
cin>>rings;
cout<<"Enter the unlocking word : ";
cin>>unlockingWord;
cout<<"Enter the secret word with underscores and the known letter: ";
cin>>secretWord;
cout<<"Enter the filename that contains the rings of letter: ";
cin>>fileName;
inFile.open(fileName);
//wrong input of fileName
if(!inFile)
{
cout<<"Error in opening file"<<endl;
exit(1);
}
string *RINGS = new string;
string letters;
for (int i=0; i<rings; i++)
{
getline(inFile,letters,'\n');
RINGS[i]=letters;
}
int index=0;
for (index=0; index<rings; index++)
{
if (secretWord[index]!='_')
break;
}
//variable "secret" indicates the position of the known letter of the secret
int a, b;
for (int j=0; j<26; j++)
if ( RINGS[index][j] == unlockingWord[j])
a=j;
for (int k=0 ; k<26 ; k++)
if (RINGS[index][k] == secretWord[index])
b=k;
int difference = b-a;//difference between the unlocking word and the secret word
int secretLetter;
cout<<"THE SECRET WORD IS ";
for (int i=0; i<rings; i++)
{
for (int j=0; j<26; j++)
{
if ( RINGS[i][j] == unlockingWord[i])
{
secretLetter=j+difference;
if (secretLetter>26)
secretLetter=secretLetter-26;
if (secretLetter<0)
secretLetter=secretLetter+26;
cout<<RINGS[i][secretLetter];
}//end of if
}//end of for
}// end of for
cout<<endl<<endl;
}//end of for
return 0;
}