入门客AI创业平台(我带你入门,你带我飞行)
博文笔记

C语言之按行读取文件

创建时间:2016-11-14 投稿人: 浏览次数:3475

原文本文件

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
");
        return false;
    }
    while(!feof(fp))
    {
        fscanf(fp,"%s",&data);
        printf("%s",data);
        printf("
");
    }
    printf("
");
    fclose(fp);
    return true;
}

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

读取效果
这里写图片描述

声明:该文观点仅代表作者本人,入门客AI创业平台信息发布平台仅提供信息存储空间服务,如有疑问请联系rumenke@qq.com。
  • 上一篇:没有了
  • 下一篇:没有了
未上传头像