Advertisement
Guest User

Untitled

a guest
Sep 22nd, 2014
173
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.66 KB | None | 0 0
  1. #include <unistd.h>
  2. #include <fcntl.h>
  3. #include <stdio.h>
  4. #include <errno.h>
  5. #include <stdlib.h>
  6. #include <string.h>
  7.  
  8. char *getline2(FILE *f)
  9. {
  10.     char buf = ' ';
  11.     int count = 1;
  12.     char *str = 0;
  13.     while ((buf = getc(f)) != '\n')
  14.     {
  15.         str = (char *)realloc(str, count*sizeof(char));
  16.         str[count-1] = buf;
  17.         count++;
  18.     }
  19.     if (count == 1)
  20.         return NULL;
  21.  
  22.     return str;
  23. }
  24.  
  25. //int main(void)
  26. //{
  27. //    FILE *f = fopen("test.txt", "r");
  28. //
  29. //    char *str = getline2(f);
  30. //    if (str == NULL)
  31. //    {
  32. //        printf("LOL!!!!");
  33. //        return 0;
  34. //    }
  35. //    puts(str);
  36. //    return 0;
  37. //}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement