首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C语言 >

c语言的一个有关问题

2012-05-28 
c语言的一个问题#include stdio.h#include string.h#define SIZE 81#define LIM 20void stsrt(char *s

c语言的一个问题
#include "stdio.h"
#include "string.h"
#define SIZE 81
#define LIM 20
void stsrt(char *strings[],int num);
int main(void)
{
char input[LIM][SIZE];
char *ptstr[LIM];
int ct=0;
int k;
printf("Input up to %d lines,and I will sort them.\n",LIM);
printf("To stop,press the Enter key at a line's start.\n");
while(ct<LIM && gets(input[ct])!=NULL && input[ct][0]!='\0');
{
ptstr[ct]=input[ct];
ct++;
}
stsrt(ptstr,ct);
puts("\nHere's the sorted list:\n");
for(k=0;k<ct;k++)
puts(ptstr[k]);
return 0;
}
void stsrt(char *strings[],int num)
{
char *temp;
int top,seek;
for(top=0;top<num-1;top++)
for(seek=top+1;seek<num;seek++)
if(strcmp(strings[top],strings[seek])>0)
{
temp=strings[top];
strings[top]=strings[seek];
strings[seek]=temp;
}
}
程序编译都通过了,但就是出不来结果,帮忙看一下。

[解决办法]
兄弟,你main()里面的while语句后面多了个分号,即
while(ct<LIM && gets(input[ct])!=NULL && input[ct][0]!='\0');
输入的值都没有保存,也太粗心了吧
[解决办法]
while(ct<LIM && gets(input[ct])!=NULL && input[ct][0]!='\0');把分号去掉,不把分号去掉相当于执行了一个空语句。所以不出来。
[解决办法]
单步调试和设断点调试是程序员必须掌握的技能之一。

热点排行
Bad Request.