运行之后,就没有之后了。第三次发帖,还没解决问题 菜菜求指点
这是我第三次发这个贴了 说明没人能帮我真正解决我的问题,我需要一个实质性的帮助 就是告诉我怎么改,我们交作业有时间限制的,这里链表和文件的问题,员工工资管理系统,把文件读入链表,我切下来单独成程序,麻烦帮忙纠正,不胜感激,下面是几经修改后的最后代码。#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;
p->next=NULL;//尾节点
pr=pr->next;//让pr指向下一个节点(但是下一个节点是否分配内存?,next指向了该类型 但是要通过malloc函数申请内存,)
printf("%d\n",pr->age);
}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("%10d %5s %2d %10s %6f\n",head->clerkNum,head->name,head->age,head->position,head->salaries);
pr=pr->next;
}
}