[c]代码库
#include<stdio.h>
#include<string.h>
int main(){
void sort(char* name[], int n);
void print(char* name[], int n);
char *name[] = {"Literally", "Completely", "Constantly", "Basically", "Pretty much"};//定义二维数组并赋初值
int n = 5;
sort(name, n);
print(name, n);
return 0;
}
void sort(char* name[], int n){
int i, j, k;
char* temp; //char类型的指针指向一行字符串
for(i = 0; i < n-1; i++){ //简单选择
for(j = i+1; j < n; j++){
if(strcmp(name[i], name[j]) > 0){
temp = name[i];
name[i] = name[j];
name[j] = temp;
}
}
}
}
void print(char* name[], int n){
int i;
for(i = 0; i < n; i++)
printf("%s\n", name[i]); //name[i]相当于这行字符串数组的数组名,而数组名就是地址
}