gpt4 book ai didi

Clang-Tidy : 'scanf' used to convert a string to an integer value, 但函数不会报转换错误;考虑改用 'strtol' (C)

转载 作者:行者123 更新时间:2023-12-05 03:45:56 27 4
gpt4 key购买 nike

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;
}

你好, friend 们,

我在我的 C 项目中遇到这个错误

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

如果你没有得到错误的原因,你能帮我吗?

最佳答案

这不是错误消息,而是来自 CLion 的警告,正如@WilliamPursell 所建议的那样,请改用 getchar。

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;
}

其他 Stack Overflow 问题

相关

关于Clang-Tidy : 'scanf' used to convert a string to an integer value, 但函数不会报转换错误;考虑改用 'strtol' (C),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65576406/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com