c语言之交换一个指针数组的值

来源:互联网 发布:怎么修改淘宝号地区 编辑:程序博客网 时间:2024/05/09 17:38
#include <string.h>#include<stdlib.h>#include <stdio.h>#define N 4int main(){    void sort(char *name[], int n);    void print(char **name, int n);    char *string[N]={"You are so handsome!!","You are the Good boy!","  I am so hot now!","I love you!"};    sort(string, N);    print(string, N);    system("pause");    return 0;}void sort(char **p,int n){    int i,j;    for (i=0;i<n-1;++i)    {        for (j=i+1;j<n;j++)        {            if (strcmp(p[i],p[j])>0)            {                char *temp = NULL;                temp = p[i];                p[i] = p[j];                p[j] = temp;            }        }    }}void print(char *name[], int n){    int i;    for(i=0; i < n; i++)    {        printf("%s\n", *(name + i) );    }}
原创粉丝点击