Advertisement
Guest User

Untitled

a guest
Jun 17th, 2019
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.54 KB | None | 0 0
  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));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement