SHARE
TWEET

Untitled

a guest Jun 17th, 2019 55 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. char * getline(FILE * fi,size_t line_length,size_t line_number)
  2. {
  3.  
  4. size_t i;
  5. char * aux_string;
  6. char * p;
  7. if (fi==NULL)
  8.     return NULL;
  9.  
  10. if ((aux_string = malloc(line_length*sizeof(char)))==NULL)
  11.     return NULL;
  12.  
  13. i=0;
  14. while(fgets(aux_string,line_length,fi)!=NULL||feof(fi)!=0)
  15.  {
  16.  
  17.     if (i==line_number)
  18.     {
  19.  
  20.         if ((p=strchr(aux_string,'n'))!=NULL)
  21.         {
  22.             *p='';
  23.         }
  24.  
  25.         return aux_string;  
  26.     }
  27.     i++;
  28.  
  29.  }
  30. return NULL;
  31. }
  32.      
  33. puts(getline(file_a,MAX_LENGTH,0));
  34. puts(getline(file_a,MAX_LENGTH,0));
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top