Listing 6 Implements strings as arrays of pointers to char
/* array6.c: Ragged arrays */ #include <stdio.h> #include <string.h> main() { char *strings[] = {"now","is","the","time"}; size_t n = sizeof strings / sizeof strings[0]; int i; /* Print from ragged array */ for (i = 0; i < n; ++i) printf("String %d == \"%s\"," "\tsize == %d," "\tlength == %d\n", i,strings[i], sizeof strings[i], strlen(strings[i])); return 0; } /* Output String 0 == "now", size == 2, length == 3 String 1 == "is", size == 2, length == 2 String 2 == "the", size == 2, length == 3 String 3 == "time", size == 2, length == 4 */ /* End of File */