jeudi 28 octobre 2021

Why does fgets not work in an "if" statement? [duplicate]

So I'm creating a program to read in data and stuck on this part. So if someone choses "1" from the menu section, it should prompt the user to enter "Name of band of Singer", but when I actually run the code, it prints the prompt but also goes back to the menu screen.

I have only copied and pasted the part where I need help in. The stuff inside "fgets" is for a struct.

int main() {
    while (1) {
        printf("The following options are available \n"
            "Read in data [1] \n"
            "Print out catalogue to screen [2] \n"
            "Save data to file [3] \n"
            "Exit Program [4] \n"
            "Enter your choice now ");
        scanf_s("%d", &menu_num);
        if (menu_num == 1) {
            printf("Name of band of Singer: ");
            fgets(hold[0].singer, 20, stdin); }

Aucun commentaire:

Enregistrer un commentaire