问题出哪了?

天地一棵树 2008-12-18 05:31:55
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
void main()
{
FILE *fp;
char str[3][10],temp[10];
int i,j,k,n;
printf("Enter string:\n");
for(i=0;i<n;i++)
gets(str[i]);
for(i=0;i<n-1;i++)
{k=i;
for(j=i+i;j<n;j++)
if(strcmp(str[k],str[j]>0)
k=j;
if(k!=i)
{strcpy(temp,str[i]);
strcpy(tstr[i],str[k]);
strcpy(str[k],temp);

}
if(fp=fopen("D:\\cc\\temp\\string.dat","w")==NULL)
{
printf("can't open file!\n");
exit (0);
}
printf("\nThe new sequence:\n");
for(i=0;i<n;i++)
{
fputs(str[i],fp);fputs("\n",fp);
printf("%s\n",str[i]);
}

}
}




...全文
60 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
落尘_55 2008-12-18
  • 打赏
  • 举报
回复
int i,j,k,n;
printf("Enter string:\n");
for(i=0;i <n;i++)
gets(str[i]); 中N没有初始化
if(fp=fopen("D:\\cc\\temp\\string.dat","w")==NULL) 中fp=fopen("D:\\cc\\temp\\string.dat","w")加个括号
等等……同意LS说的
liangkaiyu 2008-12-18
  • 打赏
  • 举报
回复
群众的眼睛总是雪亮的...

一开始定义的str是二维数组
下面又将其作一维数组用? 少见!
once_and_again 2008-12-18
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 waizqfor 的回复:]
发了两边 呵呵
if(strcmp(str[k],str[j]>0)//if(strcmp(str[k],str[j])>0)
strcpy(tstr[i],str[k]); //tstr 没被定义
if(fp=fopen("D:\\cc\\temp\\string.dat","w")==NULL)//if((fp=fopen("D:\\cc\\temp\\string.dat","w"))==NULL);



[/Quote]猛烈的错误.
feng4206yu 2008-12-18
  • 打赏
  • 举报
回复

int i,j,k,n;
...

n没有初始化或者赋值...
waizqfor 2008-12-18
  • 打赏
  • 举报
回复
发了两边 呵呵
if(strcmp(str[k],str[j]>0)//if(strcmp(str[k],str[j])>0)
strcpy(tstr[i],str[k]); //tstr 没被定义
if(fp=fopen("D:\\cc\\temp\\string.dat","w")==NULL)//if((fp=fopen("D:\\cc\\temp\\string.dat","w"))==NULL);


69,369

社区成员

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

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