I intend to store strings into an array of pointers to strings and then display them as follows :
char *directions[3];
for(i=0;i<3;i++)
scanf("%s",directions[i]);
for(i=0;i<3;i++)
printf("%s",directions[i]);
but when i run this code ,it gives me segmetation fault ,could someone please correct me?
You have an array of size 3 of pointers to characters. These pointers do not point to any valid memory where you could possibly store some of those strings that you are reading in. Trying to write to invalid memory invokes UB. Here, UB manifests in the form of a segmentation fault (most probably because you are trying to write to a location you have no control on).
Try allocating some memory first: Say a big enough buffer to read in an entire line (or the biggest string that you think you are going to encounter). Read in, allocate a
directionarray member and then copy it out as follows: