More world renowned Salem© examples....
Code:
#include <stdio.h>
int main ( ) {
// you have 5 pointers, but you can point to strings of any length
char *string1[5] = {
"a", "string", "array",
"of", "variable-length-strings"
};
// this is a pointer to anything which looks like *string1[n]
// you could also use string2 as the starting point for
// creating dynamically allocated strings using malloc
char **string2 = string1;
// you can have as many strings as you like []
// but each one must be <= 4 chars to allow the \0 to fit in [5] chars
char string3[][5] = {
"this","aray","can","only",
"hold","smal","word","type",
"str-","ings"
};
int i;
for ( i = 0 ; i < 5 ; i++ ) {
printf( "s1[%d]=%s\n", i, string1[i] );
printf( "s2[%d]=%s\n", i, string2[i] );
}
for ( i = 0 ; i < 10 ; i++ ) {
printf( "s3[%d]=%s\n", i, string3[i] );
}
return 0;
}