字符指针数组的使用及排序
程序员文章站
2022-04-24 21:07:28
...
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
using namespace std;
char* list[5]={"cattle","car","cabet","cap","canon"};
int compare(const void*a, const void*b)
{
return strcmp(*(char**)a,*(char**)b);
}
int main()
{
qsort((void*)list,5,sizeof(list[0]),compare);
for(int i=0;i<5;i++)
{
printf("%s\n",list[i]);
}
return 0;
}