A function to scan user input as string
Your code is horrible:


You don't check for end-of-file, which will lead to endless loops
You don't check for failure of malloc or realloc
You call realloc way too often, which makes the code slow for large lines of input
You cast the result of malloc
You use the outdated style of function definition from the 1980s
The variable string is not a string but points to an array of pointers to strings, which is confusing
The #include for size_t is missing
Using [0] instead of * is extremely confusing
There is no need to initialize keystroke to a space character
The parameter size is useless since the only possible value that makes sense for it is 0
The return type of the function is implicitly int, which is obsolete
The returned value is of type size_t, which doesn't fit into an int and additionally differs in signedness