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

关于C PRIMER PLUS的一个例题有关问题

2012-06-14 
关于C PRIMER PLUS的一个例题问题// sort_str.c读进一些字符串并对它们排序#include stdio.h#include s

关于C PRIMER PLUS的一个例题问题
// sort_str.c 读进一些字符串并对它们排序
#include <stdio.h>
#include <string.h>
#define SIZE 81 //字符串长度限制,包括\0
#define LIM 20 //最多读取的行数
#define HALT "" //用空字符串终止输入 这一行倒底有什么用???下面根本没有用到啊???
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 Iwill 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;
}
}


[解决办法]
留给以后用的,

或者作者/译者 根本就没看

热点排行