I had a code which works fine with the integers
#include<stdio.h>
int main()
{
int i;
int* p[5];
printf("Enter the elements to be shorted");
for(i=0;i<=4;i++)
{
scanf("%d\n",&p[i]);
}
for(i=0;i<=4;i++)
{
printf("entered [%d] integers are = %s",i, p[i]);
}
return 0;
}
produce a output
Enter the strings to be shorted1
2
3
4
5
6
enetered [0] string is = 1
enetered [1] string is = 2
enetered [2] string is = 3
enetered [3] string is = 4
enetered [4] string is = 5
but when i change limne int* p[5] to char* p[5] for using it as array of pointers to string and do the necessary changes in the above code, it produces segmentation fault.I read ian a book that we cant do this as some garbage value will be assigned to the array of pointers to string.So what can be the possible way to implement the above code with array of pointers to string.
what i want to do is get the strings as input from users and store them in array of pointers to string and then get them printed at initial stage.I am trying to code for simplest string shorting.
int *p[5]instead ofint p[5]?