-
Can anyone help?
Please, can anyone tell me what is wrong with my simple encrypter?
Code:
#include <iostream.h>
#include <fstream.h>
int main()
{
char string[256], note2[256];
int b;
cout<<"Write your note:"<<endl;
cin.getline(string, 256, '\n');
cout<<"loading..."<<endl;
for(int a=0;a<256;a++)
{
b=(int)string[a];
note2[a]=(char)(b+15);
}
ofstream a_file("note.txt");
a_file<<note2;
a_file.close();
cout<<"Your note is now encrypted into the file: 'note.txt'"<<endl;
cin.get();
return 0;
}
Thank you!
-KaibaFan321
-
> for(int a=0;a<256;a++)
1. You don't use strlen() to only output the number of chars you typed in
2. There is no \0 at the end of the string you create
-
I understood the first answer, but I didnt understand the second, I am a complete noob.
thanks
-KaibaFan321
-
note2[a] = '\0';
When you get to the end of the string
-
O, Thanks!
-KaibaFan321
PS. My teachers are going to hate this program!