//读取文件数据#define _CRT_SECURE_NO_WARNINGS#include<stdio.h>#include<stdlib.h>struct jiang{char one[50];char two[50];}str[13];void main(){//定义数据int arr[5] = { 0 };//定义文件路径char path[40] = "E:\\Look\\b.txt";//定义文件指针FILE *pf=NULL;//打开读写文件pf = fopen(path, "r");//判断是否打开文件if (pf==NULL){printf("文件打开失败!");return;}int index = 0;//读文件while (!feof(pf)){//\t就是文本中的空格,不管有多少个空格 都是一个\tfscanf(pf, "%s\t%s\n", str[index].one, str[index].two);index++;}//关闭文件指针if (pf!=NULL){fclose(pf);}for (int i = 0; i < 13; i++){printf("%s,%s\n", str[i].one, str[i].two);}system("pause");}
如果觉得《C语言 读取文件中特定数据》对你有帮助,请点赞、收藏,并留下你的观点哦!