Hi,
I read in data from a file something like this in my main function
text text
texttext texxttet
texet
char **array;
ifp = fopen (filename.txt , "r");
then I allocated some memory using malloc
for(i = 0; i < 3; i++)
{
array[i] = malloc(50 * sizeof(char));
}
then I have this
for(i = 0; i < 3 ; i++)
{
fgets(arrayString[i], 50 , ifp);
}
The contents of the file will print fine in the int main but when Im passing it in other functions I can only print the first line of the input file. For example this would print fine in int main()
for (i = 0; i < 3; i++)
{
printf("%s", arrayString[i]);
}
but when I pass this array in second function like this
PrintString(*array);
with this prototype
void PrintString(char *pArray)
When printing it in above function with code below I only get to print first line from the input file and not rest of them
for (i = 0; i < 3; i++)
{
printf("%d - %5s", i, pArray);
}
this code will show
text text
text text
text text
What am I doing wrong?