0

I'm working on a cipher project in C language. I must write 9 functions with multiple ciphering/deciphering purposes, and a main() program to test them all. Anyways, the 9 functions have been completed, they do have minor bugs but it's not what I'm here for. I thought for the main() program to test I could write a 'do-while' loop, where a variable 'test' takes input from user from 0 to 9. From 1 to 9, each value will activate a different function, and 0 ends the loop. This is my loop (I have only introduced the first function, since if it doesn't work with the first one, it won't with the others):

{
    do
        {
            if (test==1)
            {
                int n;
                char c;
                printf("Donnez le caractere:\n");
                scanf("%c", &c);
                printf("Votre caractere est: %c\n", nieme_lettre_suivante_ameliore(c,n));
            }
            printf("Rentrez a nouveau la fonction que vous voulez tester:\n");
            scanf("%d",&test);
        }
    while (test!=0);
}

Sorry it's in French, just for context, the first function will ask the user for a character 'c' and a number 'n', then if the input character is a letter it will move the letter of 'n' places in the alphabet (as in the Caesar cipher), if it is not a letter it will stop and print "this is not a letter". When I try to execute it, all printf inside the function will be printed even before the user has given his character or the number, and some of these printf shouldn't activate depending on what the user writes. I checked this outside the loop and it works fine, it only does this while inside the loop.

How do I stop this from happening, or make it wait for user input before it decides what to printf? Thank you. Please let me know if translating the text will help you help me, so I can post a translated version of the parts in French.

This is the outpout when main() is executed

BLUEPIXY
  • 39,699
  • 7
  • 33
  • 70
Paula DLT
  • 1
  • 2

0 Answers0