title: Copying the entire contents of a text file into a character array variable
body: <p>I have to place the contents of a text document called Bond.in into a character array variable.  I've tried several methods to save the contents of Bond.in into a character array, but the one that is below is the only one tha seems to work.  However, everytime I try to print the contents of the variable array using the my_getline function (a function we wrote in class that we have to use), it enters an infinite loop.  I can't figure out if this is because of the for loop that calls my_getline or if the contents of Bond.in aren't copying into text[] properly.  Any guidance would be appreciated.  Also, let me know if I left out anything that would help.</p>
  
  <pre><code>/*   Include the standard input/output and string libraries             */
  #include &lt;stdio.h&gt;
  #include &lt;string.h&gt;
  
  /*   Define the maximum lines allowed in an input text and NEWLINE for getline funct.   */
  #define MAXPATTERN 15
  #define MAXWORDS 150
  #define NEWLINE '\n'
  
  /*   function prototypes                                */
  void my_getline(char text[]);
  int find_string(char text[], char pattern[], int length_text, int length_pattern);
  
  int main()
  {
     FILE *fp;
     char text[MAXWORDS];
     int i = 0, j;
     char fileName[15] = "Bond.in";
     char pattern[MAXPATTERN], c;
     int length_text, length_pattern, count;
  
     fp = fopen(fileName, "r");
     if (fp == NULL)
     {
        printf("fopen failed.\n");
        return(-1);
     }
  
     while(feof(fp))
        text[i++] = fgetc(fp);
     text[i] = '\0';
  
     printf("%s has been copied.", fileName);
  
     for (j = 0; text[j] != EOF; j++)
     {
        my_getline(text);
        printf("%d  %s \n", j, text);
     }
  
     printf("Enter the pattern you would like to search for: ");
     scanf("%s", pattern);
     printf("\nYou have chosen to search for: %s\n", pattern);
  
     //printf("%s appears %d times in %s.\n", pattern, find_string(text, pattern, length_text, length_pattern), fileName);
     fclose(fp);
  
     return(0);
  }
  
  void my_getline(char text[])
  {
     int i = 0;
     while ((text[i] = getchar()) != NEWLINE)
        ++i;
     text[i] = '\0';
  }
  </code></pre>
  
  <p><strong>Bond.in</strong></p>
  
  <pre><code>    Secret agent Bond had been warned not to tangle with Goldfinger.
  But the super-criminal's latest obsession was too strong, too dangerous.
  He had to be stopped.
      Goldfinger was determined to take possession of half the supply of
  mined gold in the world--to rob Fort Knox!
      For this incredible venture he had enlisted the aid of the top
  criminals in the U.S.A., including a bevy of beautiful thieves from the
  Bronx.  And it would take all of Bond's unique talents to make it fail--
  as fail it must.
  </code></pre>