For whatever 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'm trying to allocate memory for a string dynamically but as I said earlier my program simply outputs (null). I worked around this by making a function using getche and realloc but it seems almost pointless due to the fact that I also had to program what would happen if the user entered backspace, tab, etc.. But as I said that is just a work around and I would rather know why the above code is not working...
Additional Information:
I am using the Pelles C IDE v7.00 and compiling with the C11 standard
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…