user input gets skipped when function is called

Viewed 13
#include <stdio.h>

int encrypt()
{
    char message[100], ch;
    int  key;
    printf("Enter a message to encrypt: ");
    gets(message);
    for (int i = 0; message[i] != '\0';++i)
    {
        ch = (message[i]);
        if (ch >= 'a' && ch <= 'z'){
            ch = ch +3;
        if (ch > 'z'){
            
        }
        message[i] = ch;
        }
        else if (ch >= 'A' && ch <= 'Z'){
            ch = ch +3;
        if (ch > 'Z')
        {
            ch = ch - 'Z' + 'A' - 1;
        }
        message[i] = ch;
        }
    }
    printf("Encrypted message: %s", message);   
    return 0;

}


int main(){
    char choice;
    printf("e or d: ");
    scanf("%c",&choice);
    
    if (choice == 'e'){
        encrypt();
    }
    else if(choice == 'd'){
        decrypt();
    }
    
    return 0;
}

output

e or d: e
Enter a message to encrypt: Encrypted message: 

I'm new to c and trying out caesars cipher. May I know why are my inputs getting skipped and the outputs are just getting printed out? I have another function called decrypt() which is similar to encrypt().I do not want to put any parameters in my function.

0 Answers
Related