Hello, I'm trying to write a program that encodes text by using what I've heard called a "Trifig cipher", for fun. Each text character is represented by 3 digits. The idea was to put the text file into an array, then loop through assigning a new, three-digit, array for each character and send the first,second, and third characters of said array into separate text files to do more magic on later. This is what I've done thusfar:
int i;
for (i=0; i < ArrayString.length(); i++)
{
int Trifig [3]= {0,0,0};
if(ArrayString[i] = 'a' || 'A'){
int Trifig [3]={1,1,1};
}else if(ArrayString[i] = 'b' || 'B'){
int Trifig [3]={1,1,2};
}else if(ArrayString[i] = 'c' || 'C'){
int Trifig [3]={1,1,3};
}else if(ArrayString[i] = 'd' || 'D'){
int Trifig [3]={1,2,1};
}else if(ArrayString[i] = 'e' || 'E'){
int Trifig [3]={1,2,2};
}
//This goes on until I get to Z
int a = Trifig [0];
int b = Trifig [1];
int c = Trifig [2];
cout<<a<<b<<c<<endl; //this is here for me to make sure it's working, it'll be deleted later
ofstream fout;
fout.open ("firstdigit.txt");
fout<< a << endl;
fout.close ();
fout.open ("seconddigit.txt");
fout<< b << endl;
fout.close ();
Now, my question is: why does my cout statement just show me a bunch of zeros? I know that's what I initialized Trifig[3] to, but if I don't initialize it to something, I get an error. I thought that my if statement would just overwrite the initialization each time it looped. Also, cout displayed double the number of lines as characters I had in the "testinput" file. I don't totally understand what "stringstream" and "str" did, I grabbed that from forum posts I read here. I've only taken a basic intro course, and I am a total noob, plagued by misconceptions.
Any help and/or insights would be very much appreciated. Thank you in advance.
Something else that pops outs is you use void main(), main ALWAYS returns a integer so this needs to be int main() and if your compiler is not shooting out a error for that I would get a new compiler ;p
And please use codetags (Hint: they are the <> off to your right when replying) it makes code much easier to read on the forums.
Yours is not looping, not sure why, made a lot of changes and put in some code to see the loops. Seems to be working but too tired to mess with it anymore tonight.
The loop seems like it's working now, but it's still putting out three zeros when the Trifig[] elements are accessed. The loop's definitely running, but it seems like the if statement isn't overwriting the initial values of Trifig[]. It should be doing that, right?