回复 6楼 embed_xuel
刚刚是急着弄程序 ,看,今天弄一天了,但是我还是没有把它成功弄出来,这是我刚刚最后修改的程序,我觉得逻辑也对,就是行不通,刚刚的帖子无意冒犯,抱歉
#include<stdio.h>
#include<stdlib.h>
struct clerk* readToLink(struct clerk* head_);
void print(struct clerk* head);
struct clerk
{
char clerkNum[10];
char name[20];
int
age;
char position[10];
char salaries[10];
struct clerk* next;
};
main()
{
struct clerk info;
struct clerk* head;
//("%d\n",sizeof(*head));
head=readToLink(&info);
print(head);
}
struct clerk* readToLink(struct clerk* head_)
{
FILE* a;
struct clerk* p=head_,*pr;
if((a=fopen("jia.txt","a+"))==0)
printf("fail to open the file!\n");
;//保存当前节点的指针//head_是头指针
do
{
pr=(struct clerk*)malloc(sizeof(struct clerk));
if(pr==NULL)
{
printf("No enough memory to allocate!\n");
exit(0);
}
fscanf(a,"%10d%5s%2d%10s%6f",pr->clerkNum,pr->name,pr->age,pr->position,pr->salaries);//按数据块读入文件//按数据块读取
//printf("%d\n",sizeof(*p));//测试p
p->next=pr;
p=pr;
}while(!feof(a));
pr->next=NULL;
fclose(a);
return head_;
}
void print(struct clerk* head)
{
struct clerk* pr=head->next;
while(pr->next!=NULL)
{
//printf("%d\n",pr->age);
printf("%10d %5s %2d %10s %6f\n",head->clerkNum,head->name,head->age,head->position,head->salaries);
pr=pr->next;
}
}