title: Data entry into array of character pointers in C
body: <p>this is my first question asked on here so if I'm not following the formatting rules here please forgive me. I am writing a program in C which requires me to read a few lines from a file. I am attempting to put each line into a cstring. I have declared a 2D character array called buf which is to hold each of the 5 lines from the file. The relevant code is shown below </p>
  
  <pre><code>#include &lt;stdlib.h&gt;
  #include &lt;sys/types.h&gt;
  #include &lt;sys/file.h&gt;
  #include &lt;sys/socket.h&gt;
  #include &lt;sys/un.h&gt;      /* UNIX domain header */
  
  void FillBuffersForSender();
  
  char buf[5][2000]; //Buffer for 5 frames of output
  
  int main()
  {
  
  FillBuffersForSender();
  
  return 0;
  }
  
  void FillBuffersForSender(){
      FILE *fp;
      int line = 0;
      char* temp = NULL;
      size_t len = 0;
      ssize_t read;
      fp = fopen("frames.txt", "r");
      printf("At the beginning of Fill Buffers loop.\n");
      //while ((read = getline(&amp;temp, &amp;len, fp)) != -1){
      while(line &lt; 5){
              //fprintf(stderr, "Read in: %s\n", temp);
              fgets(temp, 2000, fp);
              strcpy(buf[line], temp);
              line++;
              fprintf(stderr, "Line contains: %s.\n", temp);
              temp = NULL;
             }
      while(line != 0){
          fprintf(stderr, "Line contains: %s.\n", buf[line]);
          line--;
      }
  
  }
  </code></pre>
  
  <p>The line</p>
  
  <pre><code>strcpy(buf[line], temp);
  </code></pre>
  
  <p>is causing a segmentation fault. I have tried this numerous ways, and cannot seem to get it to work. I am not used to C, but have been tasked with writing a bidirectional sliding window protocol in it. I keep having problems with super basic issues like this! If this were in C++, I'd be done already. Any help anyone could provide would be incredible. Thank you. </p>