The line if (!str) return str;
basically means if (str == NULL) return NULL;
which is just error checking the return value of realloc
.
The reason we make ch
an int
is because the function fgetc
returns an int
(that is how we can have EOF
be returned yet EOF
isn't a legal char
value).
The size
argument simply represents the initial size of the buffer that we allocate. So if the person calling the function has a pretty good (not necessarily exact) idea of how big the string will be, they can give it in this parameter and save a lot of time by avoiding extra calls to realloc
.