I'm making a very simply encryption program and to decrypt I need a few things to happen:
1) I need to get input from the user and see what the encrypted message is.
-The problem is that I don't always know how long the encrypted message
is going to be. Because of this I took the user input using a char array
called: "char input[100];". Is there another way to take input in a
char but stop when a char is null?
2) Assuming there is no other way to get the char input like that, I need to change the chars to ints.
-The problem is that I don't know how to call upon each variable in the
array and say that: "char input[1] = int number1;" because I don't
know how many chars will be in the array.
3) The hard part is over, now I subtract each individual int by 5
-Because when I encrypted, I added each individual int by 5
Sorry for coming on here with a bunch of questions, but I really need help.
1) In C, no. In C++, just use an std::string.
2) An std::vector (C++) or dynamic allocation (C) is what you want here.
3) Should be easy once you get there.
You could ask the user to manually specify how long his input will be but that's nasty.
You could also read the input character by character and use realloc() and memcpy() but that's even nastier.
You could read the input from a file...
But since you're using C++ I suggest you stick to the C++ ways. std::string is a good way to go I guess.
You can use the subscript operator to access elements char c = str[2];.
char signedness always bothered me. I'd consider using std::vector<unsignedchar> if I needed to perform math on the ASCII codes.