Tag:c memory model level two pointer
#include <stdio.h> #include <stdlib.h> #include <string.h>/* third memory model for level two pointers */// Print string array Int printarray (char **arraystr,int num) { int i = 0 ; for (i=0; i<num; i++) { printf ("%s \n", Arraystr[i]); } return 0;} Sort Int sortarraystr (char **arraystr,int num) { int i = 0, j = 0; char *temp = null; for (i=0; i<num; i++) { for (j=i+1; j<num; j++) { if (strcmp (arraystr[i],arraystr[j]) < 0) { temp = arrayStr[i]; arrayStr[i] = arrayStr[j]; arraystr[j] = temp; } } } return 0;} Second-level pointer to the third memory model Int main () { int i = 0, j = 0; char buf[100]; char **arrayStr = (char **) malloc (10*sizeof (char *)); //int array[10] if (arrayStr == null) { return; } for (i=0; i <10; i++) { arraystr[i] = (char *) malloc (100*sizeof (char)); // char buff[100] if (arraystr[i] == null) { printf ("ddde\n"); return; } sprintf (Arraystr[i], "%d%d%d", I,i,i); } printf ("before ordering \ n"); printarray (arraystr,10); sortarraystr (arraystr,10); printf ("after ordering \ n"); PrintArray (arraystr,10); for (i=0; i<10; i++) { free (Arraystr[i]); } if (ArrayStr != NULL) { free (ARRAYSTR); } system ("pause"); return 0;}
C Two-level pointer memory model three