Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int fgetline(FILE * f, char ** line){
- if(f == NULL) return -1;
- if(line == NULL) return -2;
- unsigned long alloc = 32;
- *line = malloc(sizeof(char) * (alloc + 1));
- char c = 0;
- size_t i = 0;
- while((c = fgetc(f)) != '\n' && c != EOF){
- (*line)[i++] = c;
- if((i+2) >= alloc){
- alloc *= 2;
- *line = realloc(*line, (alloc + 1) * sizeof(char));
- if(*line == NULL) return -4;
- }
- }
- (*line)[i] = '\0';
- return c == EOF;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement