1 题目
函数:sort()
功能:使用指向指针的指针对字符串排序
描述:
使用指向指针的指针对字符串排序,输出是按照字母顺序进行排序
2 思路
a. 熟悉指向指针的指针的使用
char *nums[]={"", ""}; char **p; p = nums;
熟悉 *p 指向的是 nums[0] 的首地址
b. 引用模块#include <string.h>
使用函数 int strcmp(const char *str1, const char *str2) 进行字符串的比较
该函数返回值如下:
-
如果返回值小于 0,则表示 str1 小于 str2。
-
如果返回值大于 0,则表示 str1 大于 str2。
-
如果返回值等于 0,则表示 str1 等于 str2。
3 代码
#include <stdio.h> #include <string.h> #define N 10 /** 函数:fun() 功能:使用指向指针的指针对字符串排序 描述: 使用指向指针的指针对字符串排序,输出是按照字母顺序进行排序 **/ void sort(char **p) { char *temp; // 排序交换时的临时变量 for (int i = 0; i < N; ++i) { for (int j = i+1; j < N; +&