求急急急!!请高手

bookoo 2015-01-26 02:20:06
#include<stdio.h>
#include<stdlib.h>
int main()
{
typedef struct lnode{
int data;
struct lnode *next;
}node,*linklist;
linklist l;
FILE *fp,*fr;
int ch[3][2]={0};
int i=0,j=0;
fp=fopen("D:\\c.txt","r");
fr=fopen("1.txt","w");
for(i=0;i<3;i++)
{
for(j=0;j<2;j++)
{
fscanf(fp,"%d ",&ch[i][j]);
}
}
fclose(fp);
l=(struct lnode*)malloc(sizeof(struct lnode));
if(!l)
{
printf("申请内存失败!\n");
exit(0);
}
l->next=NULL;
linklist p,q,no;
p=l;
q=l;

for(i=0;j<3;i++)
{
for(j=0;j<2;j++)
{
p=(struct lnode *)malloc(sizeof(struct lnode));
p->data=ch[i][j];
q->next=p;
p->next=NULL;
q=p;
}
p=l->next;
while(p)
{
fprintf(fr,"%d ",p->data);
p=p->next;

}
fprintf(fr,"\n");

p=l;
while(l->next)
{
p=l->next;
free(l);
l=p;
}
}
fclose(fr);
}

请教:c.txt 为3行2列 数据 从小到大排列 如:1 2
4 8
9 12
在1.txt 中 能看到这些数据,但是后面还有一大排数据 不知是什么,是内存地址码??运行报错,不能引用0x00233000
是不是 ,在释放链表结点哪里出错啊???
...全文
65 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
bookoo 2015-01-26
  • 打赏
  • 举报
回复
引用 2 楼 q3733353520 的回复:

for(i=0;j<3;i++)  // for(i=0; i<3; i++)  太粗心了
{
for(j=0;j<2;j++)
{
p=(struct lnode *)malloc(sizeof(struct lnode));
p->data=ch[i][j];
q->next=p;
p->next=NULL;
q=p;
}
木哈哈, 搞了2天了,太谢谢指点了
  • 打赏
  • 举报
回复

for(i=0;j<3;i++)  // for(i=0; i<3; i++)  太粗心了
{
for(j=0;j<2;j++)
{
p=(struct lnode *)malloc(sizeof(struct lnode));
p->data=ch[i][j];
q->next=p;
p->next=NULL;
q=p;
}
FightForProgrammer 2015-01-26
  • 打赏
  • 举报
回复
你调试跟踪一下不就知道了

69,369

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧