c语言 读取txt文件

时间:2014.08.02 发布人:hgei0p6dsc5

c语言 读取txt文件

已解决问题

谷歌hgei0p6dsc5用户在2014.08.02提交了关于“沈梦辰c语言 读取txt文件”的提问,欢迎大家涌跃发表自己的观点。目前共有1个回答,最后更新于2024-10-12T20:24:00。希望大家能够帮助她。

详细问题描述及疑问:期待您的答案,滴水之恩,来日我当涌泉相报 !

希望以下的回答,能够帮助你。

第1个回答

用户名:yc71概0081934  

#include<stdio.h>
#include<stdlib.h>

#defineFilE批利知NAME"test.txt"

structpe住钢规己r
{

charfirstname[10];
charname[20];
charbirthday[11];
charhobby[10];
chartel[20];
};
intmain()
{




FILE*pfile=fopen(FilENAME,"r");
if(pfile)
{
while(!feof(pfile))
{
structper*p=(structper*)malloc(sizeof(structper));
fscanf(pfile,"%s%s%s%s%s",p->firstname,p->name,湖p->birthday,p->hobby,p->tel);
printf("%-4s\t%-4s\t%-4s\t问答%-4s\t%-4s\n",p->firstname,p->name,p->birthday,p->hobby,p->tel);
}

}

else
printf("打开文件失败");


return0;
}