C语言之按行读取文件

版权声明:本文为博主原创文章,遵循 CC 4.0 by-sa 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/kaikai_sk/article/details/53164711

原文本文件

outlook,temperature,humidity,windy,play
sunny,hot,high,FALSE,no
sunny,hot,high,TRUE,no
overcast,hot,high,FALSE,yes
rainy,mild,high,FALSE,yes
rainy,cool,normal,FALSE,yes
rainy,cool,normal,TRUE,no
overcast,cool,normal,TRUE,yes
sunny,mild,high,FALSE,no
sunny,cool,normal,FALSE,yes
rainy,mild,normal,FALSE,yes
sunny,mild,normal,TRUE,yes
overcast,mild,high,TRUE,yes
overcast,hot,normal,FALSE,yes
rainy,mild,high,TRUE,no
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>

bool ReadCsvFile(char* filePath)
{
    char data[100];
    FILE *fp=fopen(filePath,"r");
    if(!fp)
    {
        printf("can't open file\n");
        return false;
    }
    while(!feof(fp))
    {
        fscanf(fp,"%s",&data);
        printf("%s",data);
        printf("\n");
    }
    printf("\n");
    fclose(fp);
    return true;
}

int main()
{
    ReadCsvFile("D:\\MyCppProject\\weather.nominal.csv");
    return 0;
}

读取效果
这里写图片描述

展开阅读全文

没有更多推荐了,返回首页