You should write lots of little testbed programs so you can concentrate on the details of each thing.
For example:
Code:
#include <stdio.h>
#include <stdlib.h>
#define STR_MAX 256
#define STR_CNT 6
int
main (void)
{
char *buf, *data[STR_CNT];
/* don't take malloc for granted -- test it */
if ((buf = malloc (STR_MAX * STR_CNT)) == NULL)
{
fprintf (stderr, "malloc error");
exit (EXIT_FAILURE);
}
/* don't trash the alloc'd address, either */
char *tmp = buf; int i;
for (i = 0; i < STR_CNT; i++)
{
data[i] = tmp;
tmp += STR_MAX;
sprintf (data[i], "data-%d", i);
}
/* did it work? */
printf ("\n%s %s %s\n", data[0], data[1], data[2]);
printf ("%s %s %s\n\n", data[3], data[4], data[5]);
free (buf);
return (EXIT_SUCCESS);
}
This represents just one way to allocate space for an array of strings.
The point is, every program, no matter how complicated, is made up of fairly small, manageable steps -- so master those first.