Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- char *readline(FILE *in) {
- #define MAX_SIZE 512
- int size = MAX_SIZE;
- char *str = malloc(sizeof(char) * size);
- char *pos;
- while(fgets(str + size - MAX_SIZE, MAX_SIZE, in)) {
- if(pos = strchr(str + size - MAX_SIZE, '\n')) {
- *pos = '\0';
- break;
- }
- size = size + MAX_SIZE - 1;
- str = realloc(str, sizeof(char) * size);
- }
- return str;
- }
Advertisement
Add Comment
Please, Sign In to add comment