OK, keeping your format the same.... here's a fixed version.
Code:
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
int main(void)
{
char *p[8];
char line[10];
int k;
for (k = 0; k < 8; k++)
{
scanf("%s", line);
if (feof(stdin)) break;
p[k] = malloc(sizeof line);
if (p == NULL)
{
printf("storage: no storage available\n");
return(1);
}
strcpy(p[k], line);
}
for (k = 0; k < 8; k++)
{
printf("%s\n", p[k]);
free(p[k]);
}
return(0);
}
I don't recommend using scanf() to get a "line" as it won't, it will get a word (using %s, it inputs up to the next white space character.
Note that the free() is done with the for loop, this is because you malloc()'d 8 times within the previous loop. You cannot free all 8 allocations in one go.
>malloc(sizeof line)
There's no pointing in mallocing this size, the string might be shorter. Use this instead
>malloc(strlen(line)+1)
Also, malloc() requires stdlib.h
>if (feof(stdin)) break;
if you reach eof, because the user hits CTRL+d/z, you must not do the printf() loop 8 times, as the array won't have 8 valid pointers in it.