Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <unistd.h>
- #include <fcntl.h>
- #include <stdio.h>
- #include <errno.h>
- #include <stdlib.h>
- #include <string.h>
- char *getline2(FILE *f)
- {
- char buf = ' ';
- int count = 1;
- char *str = 0;
- while ((buf = getc(f)) != '\n')
- {
- str = (char *)realloc(str, count*sizeof(char));
- str[count-1] = buf;
- count++;
- }
- if (count == 1)
- return NULL;
- return str;
- }
- //int main(void)
- //{
- // FILE *f = fopen("test.txt", "r");
- //
- // char *str = getline2(f);
- // if (str == NULL)
- // {
- // printf("LOL!!!!");
- // return 0;
- // }
- // puts(str);
- // return 0;
- //}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement