Oh, and on a separate note, this:
Code:
char *string[]={
"my name is dave",
"we like to dance together",
"sunny day",
"hello",
"in the beginning god created heaven and earth",
"decleration",
"wroooong"
};
should be:
Code:
const char *string[] = {
"my name is dave",
"we like to dance together",
"sunny day",
"hello",
"in the beginning god created heaven and earth",
"decleration",
"wroooong"
};
The pointers each point to the first character of a string literal. Modifying a string literal, e.g., by changing string[0][0] to 'b', results in undefined behaviour, so to avoid such a mistake, we declare the pointers to be pointers to const char. Accordingly, you should change the type of strings2 to const char**.
If you compare to:
Code:
char string[][50] = {
"my name is dave",
"we like to dance together",
"sunny day",
"hello",
"in the beginning god created heaven and earth",
"decleration",
"wroooong"
};
Then you'll find one example of where pointers and arrays differ: string would then be an array of 7 arrays of 50 chars, hence assigning 'b' to string[0][0] is fine because it is not an attempted modification of a string literal. Furthermore, it would no longer be correct to write:
Code:
char **strings2 = strings;
because strings would be converted to a pointer to an array of 50 chars, which is not convertible to a pointer to a pointer to char.