| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 343 人关注过本帖
标题:麻烦各位帮我看看这个程序,该怎么改好呢?
只看楼主 加入收藏
小丫1988
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2009-12-27
结帖率:0
收藏
已结贴  问题点数:20 回复次数:1 
麻烦各位帮我看看这个程序,该怎么改好呢?
#include   <stdio.h>
#include<malloc.h>
#include   <stdlib.h>
#include   <string.h>

#define   LEN   sizeof(struct   WORD)

struct   WORD
{
char   word[15];
struct   WORD   *next;
};

struct   WORD   *sort(struct   WORD   *head)
{
struct   WORD   *p,   *q,   *temp;
p   =   head-> next;

if(!p)
return   head;

while(p-> next)
{
q   =   head;
while   (strcmp(q-> next-> word,   p-> next-> word)   <   0)
q   =   q-> next;
if(q   !=   p)
{
temp   =   q-> next;
q-> next   =   p-> next;
p-> next   =   p-> next-> next;
q-> next-> next   =   temp;
}
else
p   =   p-> next;
}
return   head;
}

struct   WORD   *create()
{
FILE   *fp;
char   str[15];
struct   WORD   *head=(struct   WORD*)malloc(LEN);
struct   WORD   *p   =   head;
int   n;
head-> next=NULL;


fp   =   fopen("e:\\test.txt",   "r+");
if   (fp   ==   NULL)
{
printf("can't   open   the   file\n");
exit(1);
}
n   =   fscanf(fp,   "%s",   str);

while(n   !=   EOF)
{
struct   WORD   *node=(struct   WORD*)malloc(LEN);
node-> next=NULL;
strcpy(node-> word,   str);
p-> next   =   node;
p   =   node;
n   =   fscanf(fp,   "%s",   str);
}

return(head);
}

void   print(struct   WORD   *head)
{
FILE   *fp;
struct   WORD   *p,   *q;
p   =   head-> next;

fp   =   fopen("e:\\test.txt",   "r+");
if   (fp   ==   NULL)
{
printf("can't   open   the   file\n");
exit(1);
}

while(p   !=   NULL)
{
q   =   p;
fprintf(fp,   "%s   ",   p-> word);
p   =   p-> next;
free(q);
}
free(head);
}

int   main()
{
struct   WORD   *head1;

head1   =   create();
head1   =   sort(head1);
print(head1);

system("pause");
return   0;
}
在LINUX下运行提示是:在函数“sort”中:
15:错误:赋值时类型不兼容
23:错误:“p”未声明(在此函数内第一次使用)
23:错误:(即使在一个 函数内多次出现,每个未声明的标识符在其所在的函数内也只报告一次)
该怎么改啊,谢谢高手帮忙了
  
搜索更多相关主题的帖子: next include return word 
2009-12-27 16:51
fqtb16
Rank: 7Rank: 7Rank: 7
来 自:上海
等 级:黑侠
帖 子:96
专家分:504
注 册:2009-12-28
收藏
得分:20 
你确定sort()编译有问题?
我的这个版本linux没发现这个函数里面有问题,红帽子的

爱拼才会赢
2009-12-29 06:24
快速回复:麻烦各位帮我看看这个程序,该怎么改好呢?
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.015766 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved