Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- char *str = NULL;
- size_t len = 0;
- size_t allocd = 0;
- size_t n;
- char buf[SIZ];
- while ((n = fread(buf, 1, sizeof(buf), stdin)))
- {
- allocd += n;
- str = realloc(str, allocd); // Extend the buffer
- memcpy(str+len, buf, n); // Append to the string
- len += n;
- }
- ++allocd;
- str = realloc(str, allocd);
- str[len] = 0;
- printf("ALLOC'D: %zu", allocd);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement