首页 > 解决方案 > 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;
}

标签: cdebugging

解决方案


推荐阅读