Trying to teach myself C and I'm stuck on this one. I tried:
///Next line creates 10 uninitialized pointers to strings
///Here are tring to access something unininitialized
When creating the 10 pointers, those are not assigned any values, hence
they could be pointing any memory location, possibly critical ones. The
behavior you obtain trying to access these memory zones is in general
dependent on the way your OS handle these errors and on the memory
locations.
A good but expencive way of programming for a beginner, is to set any
uninitialized variable to NULL (zero), so in your case:
#include <string.h>
...
char *array_name[10];
memset (array_name,0, 10);
This prevents unpredictable behavior. When trying to access your vector,
you will have a predictable behavior that tells you that your pointer
isn't pointing any thing.
If you feel brave enough you could let gdb handle this job for you;
specific options exist that allow gdb to clear any new variable when
created.
Once you've done that, you start populating your array by allocating
memory for the strings you want to store, with "malloc":
//reserve 8 bytes (excluding the trailing zero) and
//copy the pointer to these 8 bytes in array[2].
array[2] = malloc(strlen("helloworld"));
//copying the string
memcpy(array[2], "helloworld", strlen("helloworld"));
...
//memory deallocation (as it's not needed anymore at some point in the
//program or at exit
free(array[2]);