那位高人能告诉我这个程序错在哪里?

来源:百度知道 编辑:UC知道 时间:2024/05/12 16:21:26
程序运行时有内存错误,运行的时候需要在E盘创建个文件caozuo.txt,假如该文件中包含的内容为“a 0 0 5 3 0”,哪位高人可以帮小弟修改一下这个程序,使其先通过文件输入到一个链表,然后再输出链表第一个结点的name域,小弟不胜感激!!!

#include <iostream>
#include <fstream>
using namespace std;

typedef struct pcb{
char name[10];//进程名
int atime;//到达时间
int ftime;//结束时间
int rtime;//运行时间
int yxj;//优先级
int zhoutime;//周转时间
pcb * next;
}pcb,*ppcb;

void read(ppcb x)
{
ppcb m;
m=x;
ppcb n;
ifstream in("e:\\caozuo.txt");
while(in.eof()!=0)
{
in>>m->name;
n=new pcb;
m->next=n;
m=n;
}
n->next=NULL;
}

void printout(pcb * x)
{
cout<<x->name;
}

void main()
{
ppcb a=new pcb;
read(a);
printout(a);
}

#include <iostream>
#include <fstream>
using namespace std;

typedef struct pcb{
char name[10];//进程名
int atime;//到达时间
int ftime;//结束时间
int rtime;//运行时间
int yxj;//优先级
int zhoutime;//周转时间
pcb * next;
}pcb,*ppcb;

void read(ppcb x)
{
ppcb m;
m=x;
ppcb n;
ifstream in("e:\\caozuo.txt");
while(!in.eof()) //具体程序没看,这里改了一下
{
in>>m->name;
n=new pcb;
m->next=n;
m=n;
}
n->next=NULL;
}

void printout(pcb * x)
{
cout<<x->name;
}

void main()
{
ppcb a=new pcb;
read(a);
printout(a);
}

解决方法:一键恢复,或重装机子