c - error: 'fscanf' 用于将字符串转换为整数值,但函数不会报告转换错误;考虑改用“strtol”
问题描述
我正在尝试使用此代码打印出一个文件,但我不断收到要求我在 clion 上使用 strtol 而不是 fscanf 的错误。
#include <stdlib.h>
#include <stdio.h>
#define SSIZE 20
int main(void) {
FILE *fin;
int i;
float f;
char string[SSIZE];
/* maximum SIZE of string, including NUL */
/* define a file pointer */
/* define variables to store data */
fin = fopen("data.txt", "r");
fscanf(fin, "%d %f %s", &i, &f, string);
/* open data.txt file for read */
/* read file and save data to variables */
printf("%d %f %s\n", i, f, string);
/* print values of variables to screen */
fclose(fin);
/* close file properly */
return 0;
}
解决方案
推荐阅读
- java - 如何构建 Java `Map
` 出 ` 列表 >`? - python - 使用 __file__ 时出现 Python 错误 [WinError 123](文件名、目录名或卷标语法不正确)
- firebase - 无法从 Firebase 控制台下载 google-services.json
- python - 使用递归时,列表不会添加任何新元素
- opengl - glMapBuffer 在 Mac 上返回 NULL,在 Windows 上工作得很好
- c++ - 我以后可以将我的 Visual C++ win32 项目转换为跨平台吗?
- java - Android:如何使用卡片视图而不是按钮
- php - Laravel 5.5 - 读取存储在外部文件夹中的图像
- java - Spring Security @PreAuthorize 基于自定义布尔属性值
- postgresql - 是否可以限制用户在 PostgreSQL 数据库中更改运行时配置参数的能力?