首页 > 解决方案 > C - 涉及 fscanf 的不需要的输出

问题描述

我正在做我的学校作业,我遇到了 fscanf 的问题,可以说是文件管理。我一直在这几个小时,查找各种功能和 fscanf 本身,我仍然无法解决这个问题。

#include<stdio.h>

int main()
{
    FILE *f3;
    float amount_with[100][30];
    int j;
    char date_with[100][30];

    f3 = fopen("withdrawals.txt", "r");
    if (f3 == NULL)
    {
        printf("ERROR! File could not be opened.\n");
    }

    for(j=0; j <= 50 || !feof(f3); j++)
    {
       fscanf(f3, "%s %f", date_with[j], &amount_with[j]);
       printf("%d %s RM %.2f", j+1, date_with[j], amount_with[j]);
    }
}

我想向程序输入一行浮点数、整数和字符串的数据。(例如,本程序中的 18/11/18 200.00)通过 fscanf 或任何其他可能的方式从文本文件中获取。但是,当我执行代码时,程序挂起,除了 CTRL+C 之外,我无法在其中执行任何操作。

谢谢你的帮助。

标签: carraysdebuggingscanf

解决方案


推荐阅读