cin.getline() get from standard input. To input from the file, use infile.getline(coded, 13);
The variable i should really be an int, in your latest attempt you've made it a char.
You should check that the file open worked successfully too, before trying to input from it. Something like:
Code:
ifstream infile("ceas.dat"); // Opens the file with the coded text
if (!infile)
{
perror("ceas.dat");
return (0);
}
As for the layout, personally I'd lay your code out like this, but it's only my preference.
Code:
// Written by Phillip Hermans
// Ceasar Cipher
// Feburary 13, 2003
#include <iostream.h>
#include <fstream.h>
int main(void)
{
char coded[13];
char decode[13];
int i;
ifstream infile("ceas.dat"); // Opens the file with the coded text
if (!infile)
{
perror("ceas.dat");
return(0);
}
infile.getline(coded, 13);
for (i = 0; i < 12; i++)
{
coded[i] += 3;
if (coded[i] > 90)
{
coded[i] = (coded[i] - 90) + 65;
}
}
ofstream fout("unco.dat"); // Opens a new file with the decoded text
fout << coded;
fout.close();
cout << decode;
return(0);
}
hmm... you still don't seem to be checking for 0x00 when you do the +3 bit?!
Let me get this straight, you have a file that contains encoded text, you want to open it, decode the text and write that out to another file. Right?