Okay, so I have said code:
#include <iostream>
#include <cstdlib>
using std::cout;
using std::cin;
using std::endl;
int main()
{
char input[8];
int counter = 0;
int newletter;
do
{
cout << "Please enter a 7 letter word to encrypt:\n>";
cin >> input;
if(input[8] != '\0')
{
input[8] = '\0';
}
}while(input[8] != NULL);
while(counter <= 6)
{
newletter = input[counter];
input[counter] = ++newletter;
counter++;
}
cout << "your encrypted word is:\n" << input << endl;
system("PAUSE");
return 0;
}
and I would like to know about the NULL terminator. The above program is a homework assignment where we need to encrypt a string. great, that part works perfectly, and thats not what I'm here about, my homework is done and turned in.
What I would like to know is:
if the user inputs a string that is more than 7 characters long, it can mess up the program. I tried to do something above where it basically says "If the last character that the array can store is not the character that ends the array, make it so;" but yet, it doesn't do so...
Am I wrong in thinking that the below statement should work?
do
{
cout << "Please enter a 7 letter word to encrypt:\n>";
cin >> input;
if(input[8] != '\0')
{
input[8] = '\0';
}
}while(input[8] != NULL);
((pardon that if statement in there... I was trying a few things, but it should still run the loop just fine, if my logic is right..))
If someoen could set me on the straight and narrow, that would be great... thanks :)
Derek Elensar