The second-level pointer identifies the largest character:
#include <stdio.h>
char maxchar(char * str, char** max)
{
Char da = * STR; // first run the maximum first character
*max = str;
while (*str)
{
if (*str > da)
{
da = *str;
*max = str;
}
str++;
}
return da;
}
int main()
{
char str[] = "hello liuwxeia";
char * max = NULL;
char ch = maxchar(str, &max);
printf("%p\t%c\n", max, ch);
printf("%p\n", &str);
return 0;
}
Pointer array: each element in the array is a pointer.
Int * A [5]; // A is an array. The five elements are pointer to int * D // sizeof (a) -----------> 20 bytes. Because a is an array, not a pointer // a pointer contains 4 bytes
Sort string Arrays:
#include <stdio.h>
void show_str(char **s, int n)
{
int i;
for (i = 0; i < n; i++)
{
printf("%s\n", s[i]);
}
}
void sort_str(char **s, int n)
{
int i, j, min;
char * temp;
for (i = 0; i < n; i++)
{
min = i;
for (j = i + 1; j<n; j++)
if (strcmp(s[min], s[j]) > 0)
min = j;
temp = s[min];
s[min] = s[i];
s[i] = temp;
}
}
int main()
{
char *s[] = { "hello", "world", "liuwei", "xuanyuan", "nima" };
show_str(s, 5);
sort_str(s, 5);
printf("*****************\n");
show_str(s, 5);
return 0;
}
PS: the second-level pointer in the parameter is equivalent to the pointer array.
Two-dimensional arrays are equivalent to array pointers.
From Weizhi note (wiz)
8.2 list pointer Array