title: read file line by line in C(without using fgets)
body: <p>I have a file with 3 lines in it, I'm tring to read this file and save each line as a separate string.
  here is what I tried to do, it does save the first line but it overrides it by saving the first line and the second line' and I can't get my head around on how to do save each line as an individual string , and also I'm getting an error-></p>
  
  <blockquote>
    <p><strong>* stack smashing detected *</strong>: /home/ubuntu/workspace/ex12.c.o terminated
    Aborted</p>
  </blockquote>
  
  <pre><code> #include &lt;stdio.h&gt;
   #include &lt;fcntl.h&gt;
   #include &lt;stdio.h&gt;
   #include &lt;stdlib.h&gt;
   #include&lt;stdio.h&gt; 
   #include&lt;fcntl.h&gt; 
   #include&lt;errno.h&gt; 
   #include &lt;unistd.h&gt;
   extern int errno;                               
  int main( int argc, char *argv[] )  {
      char *path1;   
      char  firstline[80];
      char  secondline[80];
      char  thirdline[80];  
  
      printf("Program name %s\n", argv[0]);
  
      if( argc == 2 ) {
           printf("The path of the config file that you supplied is %s\n", argv[1]);
      }
      else if( argc &gt; 2 ) {
          printf("Too many arguments supplied.\n");
      }
      else {
          printf("One argument expected.\n");
      }
  
      int fd1 = open(argv[1], O_RDONLY | O_CREAT);  
  
      if (fd1 ==-1) 
      { 
          // print which type of error have in a code 
          printf("Error Number % d\n", errno);  
  
          // print program detail "Success or failure" 
          perror("Program"); 
          exit(EXIT_FAILURE);
      }       
      else {            
          char c;
          int i=0;            
  
          while ((read(fd1, &amp;c, 1) == 1) )
          {                
              firstline[i++]=c;                
              if(c=='\n')
              {
                  //printf("end of line"); 
                  printf("%s",firstline);
              }
  
          }
      }
      int close(int fd1);         
      return 0;        
  }
  </code></pre>
  
  <p>NOTE: I DO NOT WANT to use fopen,fgets,sscanf or getline. 
  Any help would be appreciated </p>