I've been trying to program a simple encryptor but i have some problems with the C-strings and spaces, can you help me find the mistake, because i can't.
When i try to encrypt sentences with several words it only work with the first one and leaves the rest untouched.
int main()
{
char s[100]; //Vector que contendrĂ¡ a la cadena a encriptar
char a; //Caracter para opciones
cout << "ingrese una palabra o palabra que desee encriptar (100 caracteres maximo):" << endl;
cin.getline(s, 100);
cout << endl
<< "Elija con que metodo quiere encriptarla:" << endl
<< "a) Encriptador del Cesar." << endl
<< "b) Cifrado Atbash." << endl;
do{
cin >> a;
if (a != 'a' && a != 'b')
{
cout << "Opcion incorrecta, vuelva a intentar." << endl << endl;
}
}while(a != 'a' && a != 'b');
if (a == 'a')
{
Encriptar_cesar(s);
cout << s << endl << endl
<< "Desea recuperar su cadena(a) o salir del programa directamente(b)?" << endl;
do{
cin >> a;
if (a != 'a' && a != 'b')
{
cout << "Opcion incorrecta, vuelva a intentar." << endl;
}
if (a == 'a')
{
Desencriptar_cesar(s);
cout << s;
return 0;
}
if (a == 'b')
{
return 0;
}
}while(a!='a' && a!='b');
}
I also suggest you clean up your switch statement. Putting so much on one line makes following the logic very difficult. I recommend putting everything on it's own line: