Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- char *readline(FILE *fp) {
- char buff[BUFFSIZE];
- int len;
- int copylen;
- char *ln;
- char *str;
- char *ptr;
- len = BUFFSIZE;
- str = malloc(len*sizeof(*str));
- while(fgets(buff, BUFFSIZE, fp) != NULL) {
- if((ln = strchr(buff, '\n')) != NULL) {
- copylen = ln - BUFFSIZE;
- if((ptr = realloc(str, len + copylen)) == NULL) { //FAIL }
- strncat(str, buff, copylen);
- return str;
- }
- else {
- len += BUFFSIZE;
- if((ptr = realloc(str, len)) == NULL) { //FAIL }
- strcat(str, buff);
- }
- }
- }
Add Comment
Please, Sign In to add comment