思路
先将字符串中的单词分割保存至二维数组中,再经排序后输出。水题,直接上代码了。
代码
/************************************************************************* > File Name: words_sort.c > Author: KrisChou > Mail:zhoujx0219@163.com > Created Time: Sun 24 Aug 2014 08:41:42 PM CST ************************************************************************/ #include <stdio.h> #include <stdlib.h> #include <string.h> #define N 128 #define WORD_CNT 128 #define WORD_LEN 256 static int my_isspace(char c) { if(c == ' '|| c == ' ' || c == ' ' || c == 'v') return 1; else return 0; } static void word_show(char(*words)[WORD_LEN],int cnt) { int index; for(index = 0; index < cnt; index++) { printf("%-15s", words[index]); } } static void word_save(char *line, int bg, int end, char *dest) { int index,index_dest; for(index = bg,index_dest = 0; index <= end; index++,index_dest++) { dest[index_dest] = line[index]; } dest[index_dest] = '