1
I’m trying to make a program that encodes and decodes strings that are given by the user by the César cipher method, using switch-case to select what should be done, but when trying to read a string within the case (only within the case does this occur) the program ignores the scanf and goes straight to the next line. I already tried everything I knew and nothing worked, any help would be welcome.
The text and message strings are both of size 50, Alf is a string that contains the alphabet, key is an int that is the number of houses that are advanced in the given message.
My code is like this:
case 1:
printf("Digite sua Mensagem\n");
scanf("%[^\n]s",texto);
strcpy(mensagem,texto);
printf("Digite a Chave de Codificação\n");
scanf("%d",&chave);
for(i=0;i<strlen(texto);i++) //loop p/ cada caractere da mensagem inicial
for(j=0;j<strlen(alf);j++){ //loop p/ cada caractere da mensagem inicial
if(texto[i]==alf[j]){
mensagem[i]=alf[j+chave];
break;
}else if(texto[i]==toupper(alf[j])){
mensagem[i]=toupper(alf[j+chave]);
break;
}else if(isspace(texto[i]))
break;
}
system("cls");
printf("A Mensagem Encriptada É:\n");
printf("%s\n",mensagem);
system("pause");
break;
Are you sure the input buffer is really empty? There’s no ' n' left from any previous reading there?
– Anonimo