失眠网,内容丰富有趣,生活中的好帮手!
失眠网 > C语言 读取文件中特定数据

C语言 读取文件中特定数据

时间:2021-09-12 23:23:46

相关推荐

C语言 读取文件中特定数据

//读取文件数据#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语言 读取文件中特定数据》对你有帮助,请点赞、收藏,并留下你的观点哦!

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。