Clang-Tidy: 'scanf' used to convert a string to an integer value, but function will not report conversion errors; consider using 'strtol' instead (C)

Viewed 1930
int SchedulingMethodSubMenu(struct linkedList process[], int quantumTime, FILE *fp,FILE *fr,char *ovalue,char line[LINE_MAX])
{
    printf("1)Go Back to Home \n");
    printf("2)Exit \n");
    printf("Option >");

    int choice;
    scanf("%d", &choice);
    while (choice != 1 && choice != 2)
    {
        scanf("%d", &choice);
    }
    if (choice == 1)
    {
        system("clear");
        SchedulingMethodMenu(process, quantumTime, fp, fr, ovalue, line);
    } else if (choice == 2)
    {
        system("clear");
        exit(0);
    }
    return 0;
}

Hello, friends,

I get this error in my C project

Clang-Tidy: 'scanf' used to convert a string to an integer value, but function will not report conversion errors; consider using 'strtol' instead (C++)

Can you help me if you didn't get the cause of the error?

1 Answers

This is not an error message but as Warning from CLion, as suggested by @WilliamPursell use getchar instead.

int SchedulingMethodSubMenu(struct linkedList process[], int quantumTime, FILE *fp,FILE *fr,char *ovalue,char line[LINE_MAX])
{
    printf("1)Go Back to Home \n");
    printf("2)Exit \n");
    printf("Option >");

    int choice;
    choice = getchar();
    while (choice != 1 && choice != 2)
    {
        choice = getchar();
    }
    if (choice == 1)
    {
        system("clear");
        SchedulingMethodMenu(process, quantumTime, fp, fr, ovalue, line);
    } else if (choice == 2)
    {
        system("clear");
        exit(0);
    }
    return 0;
}

Other Stack Overflow questions

Related

Related