I was trying to input an array of strings using pointers but failed. Here is the code:
int i=0;
char *p[6]; //array of strings
for(i=0;i<5;i++)
{
gets(p[i]); // input string
}
for (i=0;p[i];i++){
printf(p[i]); // print string
printf("\n");
}
The problem is that each time the first for loop executes, i input string from console, but p shows to contain NULL only. It does not contain the strings that I enter from console. The second loop does not execute, simply jumps out of the loop at first iteration since p[0] (and p[1], p[2] so on may be) contains NUll. Where is the problem? How can I correct it? Can anyone help me?