For some reason, the following code prints (null):
#include <stdio.h> #include <stdlib.h> int main(void) { char *foo; scanf("%ms", &foo); printf("%s", foo); free(foo); }
I am trying to allocate memory for a string dynamically, but as I said earlier, my program just outputs (null). I worked on this by executing a function using getche and realloc, but this seems almost pointless due to the fact that I also had to program what happens if the user enters backspace, tab, etc. But, as I said, this is just a job and I would rather know why the code above does not work ...
Additional Information:
I am using Pelles C IDE v7.00 and compiling with the C11 standard
source share