字符串排序

#include 
#include 
#include 





int com(const void *p1, const void *p2)
{
	const char **pstr1 = p1;
	const char **pstr2 = p2;//转化类型
	return strcmp(*pstr1, *pstr2);
}

void main() {
	char *str[10] = { "calc","apple","run","123","dead","father","son","hello","world" };

	qsort(str, 10, 4, com);
	for (int i = 0; i < 10; i++)
	{
		puts(str[i]);
	}

	system("pause");
}

你可能感兴趣的:(字符串排序)