What I'm trying to do is read data in from a file into an array of strings then print out that array. I had to dynamically allocate the memory without knowing how many strings are in the file, so i'm trying to find the number of strings first to pass to GetMemory ().

This is my code so far an it doesn't work. I don't really know what I'm doing here.

Code:
#include <stdlib.h> 
#include <stdio.h> 
 
int main (int argc, char** argv) 
{ 
   int s, t; 
   int numStrings = 0; 
   int i = 0; 
   FILE *ifp; 
   char string[50]; 
   char temp[50]; 
 
   /* Check correct number of command line arguments */ 
   if (argc != 2) 
   { 
      fprintf (stderr, "This program requires a command line argument\n"); 
      fprintf (stderr, "that is the name of the input file to be\n"); 
      fprintf (stderr, "used.\n"); 
      exit (-1); 
   } 
 /* Open the input file */ 
   ifp = fopen (argv[1], "r"); 
   if (ifp == NULL) 
   { 
      fprintf (stderr, "Couldn't open input file:\n"); 
      fprintf (stderr, "%s\n", argv[1]); 
      exit (-2); 
   }    
    
   while ( (fgets (temp, 50, ifp) ) != EOF) 
   { 
     numStrings++;  
      t = fgets (temp, 50, ifp); 
   }    
 
   GetMemory (numStrings, &string); 
 
   /* copy characters from input file */ 
   while ( (fgets (string, 50, ifp) ) != EOF) 
   { 
      string[i] = s; 
      i++; 
     s = fgets (string, 50, ifp); 
      fprintf (stderr, "%s", string[i]); 
   }  
 
   /* Close the file */ 
   fclose (ifp); 
 
   return 0; 
}  

/********************************************** 
* Function: GetMemory 
* 
* This function gets the memory space needed and 
* modifies the pointer that will point to it in 
* the calling function using call by reference 
* 
* Inputs: Number of characters for which to allocate 
*         space, and the pointer to the pointer that 
*         will point to the memory 
* Outputs: None 
**********************************************/ 
void GetMemory (int count, char **stringPtr) 
{ 
   /* malloc the memory and set the caller's pointer to point to it */ 
   *stringPtr = (char *) malloc( count * sizeof(char) ); 
   if (*stringPtr == NULL) 
   { 
      fprintf(stderr, "Out of memory.\n"); 
      exit (-1); 
   } 
}
Please help me fix this. Thank you for your time.