ikegami

Untitled

Jan 14th, 2021
419
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.     char *str = NULL
  2.     size_t len = 0;
  3.  
  4.     size_t n;
  5.     char buf[SIZ];
  6.     while ((n = fread(buf, 1, sizeof(buf), stdin)))
  7.     {
  8.         str = realloc(str, len + n + 1);   // Extend the buffer
  9.         memcpy(str+len, buf, n);           // Append to the string
  10.         len += n;
  11.     }
  12.  
  13.     str[len] = 0;
  14.  
  15.     printf("ALLOC'D: %zu", len);
  16.  
RAW Paste Data