vsc++ 6.0 问题。

gjw1104 2016-12-23 10:59:11
#include<stdio.h>
#include<time.h>
#include<stdlib.h>
typedef struct a
{
char d[1024];
char b;
struct a* next;
}s;//定义结构体
s * creat(int *length)//通过链表加载文本并存储到内存空间中.
{
s *head,*p,*c;
head=(s*)malloc(sizeof(s));
head->next=NULL;
c=head;
FILE *fp;
fp=fopen("data.txt","r");
while(!feof(fp))
{
p=(s*)malloc(sizeof(s));
fscanf(fp,"%c",&(p->d));
if(feof(fp))
{
free(p);
break;
}
(*length)++;
c->next=p;
p->next=NULL;
c=p;
}
fclose(fp);
return head;
}
void change(s *head,int length)//输入字符串和n,将字符串插入n次,每次随机插入到文本中.
{
int k;
s *p,*c;
p=(s*)malloc(sizeof(s));
gets(p->d);
int n,j;
srand(time(0));
int i;
scanf("%d",&n);
for(i=1;i<=n;i++);
{
k=1;
c=head;
j=rand()%(length+1)+1;
for(k;k<j;k++)
{
c=c->next; //找到插入点前一个.
}
p->next=c->next;
c->next=p;
}
}
void save(s *head) //存盘.
{
s *p;
p=(s*)malloc(sizeof(s));
p=head->next;
FILE *fp;
fp=fopen("data.txt","w");
while(p!=NULL)
{
fprintf(fp,"%s",p->d);
p=p->next;
}
fclose(fp);

}
void main()
{
int length=0;
s *head;
head=creat(&length);
change(head,length);
save(head);
}
编译连接 都没错。 为什么 运行的时候停止出错。 有没有大神。
...全文
1249 回复 打赏 收藏 转发到动态 举报
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复

1,978

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 其他语言讨论
社区管理员
  • 其他语言社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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