vendredi 1 mai 2015

If statement being ignored in main function [duplicate]

This question already has an answer here:

I'm currently writing a code in C and my if statement in main function is being ignored. As you can see, this code receives some string as input and applies the Caesar's Cipher. Note: Function ciphering called in main is also defined, I just don't paste because I don't think it is necessary because the problem is that when I ask the user if he wants to encrypt or decrypt the text, after fgets the if statement is completely ignored (after writing "encrypt" the program just quits). The code is the following:

int main()
{
    char text[SIZE], choice[SIZE];
    printf("\nWelcome to Caesar's Cipher.\nDo you wish to encrypt or decrypt text?\n");
    fgets(choice, SIZE, stdin);
    if (strcmp(choice, "encrypt") == 0)
    { 
        printf("Insert text to encrypt:\n");
        fgets(text, SIZE, stdin);
        ciphering(text);
        printf("\nThis is your text encrypted with Caesar's Cipher:\n%s\n", text);
    }
    return 0;
}

Aucun commentaire:

Enregistrer un commentaire