c - Clang-Tidy: 'scanf' 用于将字符串转换为整数值,但函数不会报告转换错误;考虑改用“strtol”(C)
问题描述
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;
}
大家好,
我在我的 C 项目中收到此错误
Clang-Tidy: 'scanf' 用于将字符串转换为整数值,但函数不会报告转换错误;考虑改用“strtol”(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;
}
其他堆栈溢出问题
有关的
推荐阅读
- javascript - 如何设置阿波罗客户端:签入反应?
- javascript - 如何在 Vue.js 中加载数据之前延迟“未找到”错误
- ruby - 如何使用 Apps Script API 创建和执行函数
- node.js - 是否可以使用 Node.js 将地图直接保存到磁盘?
- javascript - *可能的未处理承诺拒绝(id:0):类型错误:未定义不是对象(评估'result.cancelled')云图像上传
- node.js - 为 Node.js 和 React.js 部署到 App Engine 设置 app.yaml 文件
- javascript - Web Bluetooth Api - 为什么我无法检测到移动蓝牙
- javascript - 点击标签时防止默认
- python - 无法让格式函数在 python 中工作
- swift - SQLite.Swift:为值不为空的列值获取空值