#include <stdio.h>
#include <string.h>
int main()
{
int i = 0,j = 0;
char *temp = NULL;
//定义一个字符指针数组
char *pstr[5]= {"dddd","cc","bbb","aaaaa","ffffff"};
printf("Original string:");
for(i = 0;i < 5;i++)
{
printf("%s\t",pstr[i]);
}
//printf("%c\t",*pstr[0]); //*pstr[0]
puts("");
//strcmp比较大小进行排序
for(i = 0;i < 5-1;i++)
{
for(j = 0;j < 5-1-i;j++)
{
if(strcmp(pstr[j],pstr[j+1]) >= 0)
{
temp = pstr[j];
pstr[j] = pstr[j+1];
pstr[j+1] = temp;
}
}
}
printf("Strcmp after:");
for(i = 0;i < 5;i++)
{
printf("%s\t",pstr[i]);
}
puts("");
//srelen比较长度进行排序
for(i = 0;i < 5-1;i++)
{
for(j = 0;j < 5-1-i;j++ )
{
if(strlen(pstr[j]) > strlen(pstr[j+1]))
{
temp = pstr[j];
pstr[j] = pstr[j+1];
pstr[j+1] = temp;
}
}
}
printf("Strlen after:");
for(i = 0;i < 5;i++)
{
printf("%s\t",pstr[i]);
}
puts("");
return 0;
}
字符指针数组,
#include <stdio.h>
int main()
{
//定义一个长度为5的字符指针数组,
char* pstr[5] = {"hello","china","xian","nanjing","chengdu"};
//进行访问
printf("%s\n",pstr[0]); // hello
printf("%s\n",*pstr); // hello
printf("%c\n",**pstr); // h
printf("%c\n",*(*pstr+1)); // e
printf("%c\n",*(*(pstr+1))); // c
return 0;
}
以上若是都能深刻理解,那数组指针也能对比指针数组做相应理解