I am writing a caesar cipher program. It can compile but it execute something weird. I have no idea what did i do wrong here, because when I test this part
Could use some more info than that.
Also the smaller you can make the test code to show us the easier it is to help you. Debugger helps for that.
char cipher[sizeof(text)];
Just glancing through this probably isn't what you want. text.size() will give you how long the string is, sizeof will just tell you how much memory the string class takes up. Not really sure why you want to use a char array anyway, just stay with using strings?
as James2250 said, your array is too small to hold the sentence, you end writting out of bounds.
Also, you forgot to add the '\0' terminator.
> if I use string cipher
If you have an issue with another code then post that other code. It's hard to guess your mistakes.
If the only change is char cipher[sizeof(text)]; -> string cipher; then that string is empty and trying to access its elements with [] will be out of bounds.
I did some change to my code, and now it works fine if I type the sentence manually. But if I input a text file in, the output file contains nothing. Did I do something wrong to input file?