调用特定函数后,两次执行while循环

我编写了下面的函数,该函数很好地适用于所有参数,而不是调用InteractiveCredentialDispathcer。调用此函数时,将从顶部再次执行循环,然后再次执行所有检查。我应该如何解决这个问题?

void InteractiveMode()
{
    char commands[MAX_PATH] = { 0 };
    PrintColorful(0, "%s", PTH_CMD);

    while (fgets(commands, MAX_PATH - 1, stdin) != NULL)
    {
        if (strstr(commands, "help") || strstr(commands, "?"))
        {
            ShowHelpMessage();
        }
        else if (strstr(commands, "clear"))
        {
            ClearConsoleOutput(GetStdHandle(STD_OUTPUT_HANDLE));
        }
        else if (strstr(commands, "privilege"))
        {
            ShowPrivilegeStatus();
        }
        else if (strstr(commands, "login"))
        {
            if (InteractiveCredentialDispatcher())
            {
                NormalMessage("%s\n", "Process has been spawned successfully");
            }
            else
            {
                ErrorMessage("%s\n", "Process has not been spawned successfully");
            }
        }
        else if (strstr(commands, "version"))
        {
            ShowProgramVersion();
        }
        else if (strstr(commands, "exit"))
        {
            NormalMessage("%s\n", "Program has been finished.");
            ProgramExit();
        }
        else
        {
            printf("\n");
            ErrorMessage("%s\n\n", "The command isn't appropriate:");
            printf("\t");
            NormalMessage("%s\n", "You entered a blank input or a wrong command.");
            printf("\t");
            NormalMessage("%s\n\n", "Execute help or ? command to see the manual.");
        }
        PrintColorful(0, "%s", PTH_CMD);
    }
}