//
Main.c
Pointer_array
//
Created by Ma C on 15/8/2.
Copyright (c) 2015 BJSXT. All rights reserved.
Requirement: Use pointer pointer to output string. You first use a pointer array to create an array of strings, and then define a pointer pointer to the string array and use the string in its output array. At the same time, the contents of the array are sorted in ascending order.
#include <stdio.h>
#include <string.h>
void Ascsort (char **arr,int len)//Receive pointer type array, and length
{
for (int i=0;i<len-1;i++)
{
for (int j=0;j<len-1-i;j++)
{
if (strcmp (arr[j],arr[j+1]) >0)//Ascending sort
{
Char *temp = arr[j];
ARR[J] = arr[j+1];
ARR[J+1] = temp;
}
}
}
}
void PrintArray (char* arr[],int Len,char **p)
{
for (int i=0;i<4;i++)
{
printf ("%s", * (P+i));
}
printf ("\ n");
}
int main (int argc, const char * argv[])
{
char* str[]={"Jony", "Tom", "Smith", "Boy"}; //array of pointer types
Char **p;//defines pointer variables that point to pointers
p = str;
printf ("Before sorting:");
PrintArray (STR,4,P);
Ascsort (str,4);
printf ("After sorting:");
PrintArray (STR,4,P);
return 0;
}
The C language is sorted by pointers to array elements