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?

>>PrintString(*array);
That is not an array of strings like you originally declared because it only has one asterisk. All that takes is one character array. If you want it to print all the strings then you need it like this: printString(char **array); or this printString( char* array[]);

Comments
thanks for the help

Make the prototype: void PrintString(char **pArray) add an extra *

Call the function as: PrintString(*array); remove the *


Display each subscript of the pointer: printf("%d - %5s", i, pArray[i] ); add the individual pointer subscript

Comments
thanks

Thanks for the help. It worked!

Now Im trying to pass the read string into another function needs to check if its palindrome and count how many vowels are in it.

would I pass it in like this for string 3

PalindromeCheck(array[2])

And how should I check if string is palindrome. I just need some hints
thanks

This question has already been answered. Start a new discussion instead.