samedi 2 mai 2015

How not to use else main()?

I'm writing this code:

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\n") == 0)
    { 
        printf("\nInsert text to encrypt:\n");
        fgets(text, SIZE, stdin);
        ciphering(text);
        printf("\nThis is your text encrypted with Caesar's Cipher:\n%s\n", text);
    }
    else if (strncmp(choice, "decrypt", 7) == 0)
    { 
        printf("\nInsert text to decrypt:\n");
        fgets(text, SIZE, stdin);
        deciphering(text);
        printf("\nThis is your text encrypted with Caesar's Cipher:\n%s\n", text);
    }
    else main();
    return 0;
}

But the line else main() seems ugly and not correct. Should I change the code? If so, how? Or is that okay?

Aucun commentaire:

Enregistrer un commentaire