3
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?

the busybee
  • 10,755
  • 3
  • 13
  • 30
  • [Sample `strtol()`](https://stackoverflow.com/a/63503107/2410359). The best solution: drop `scanf()` everywhere in code, use `fgets()` to read user input and then `strtol()` for this function. I suspect that is too big a change for you though and the [real problem](https://stackoverflow.com/questions/65576406/clang-tidy-scanf-used-to-convert-a-string-to-an-integer-value-but-function-w#comment115942644_65577066) you are having is not in this portion of code. – chux - Reinstate Monica Jan 05 '21 at 11:26
  • 2
    Did you read the documentation on `scanf()`? And did you think about the result, if the user enters something unexpected? The diagnosic message is clear on the topic: _[scanf()] will not report conversion errors_ – the busybee Jan 05 '21 at 11:44
  • 1
    You don't need `scanf` here, and even `fgets` is overkill. Just use `getchar`. – William Pursell Jan 05 '21 at 12:00

1 Answers1

3

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

Federico Baù
  • 6,013
  • 5
  • 30
  • 38