Why writing to a FILE stream return random number?
I have the following code to open a buffer in the memory and write some
data to it:
int main() {
char buf[1000] = {0};
FILE * os = fmemopen(buf, 1000, "w");
fprintf(os, "%d", 100);
fclose(os);
printf("%d\n", buf);
return 0;
}
The output is some random numbers such as : 895734416 or a negative
number... why is this happening?
No comments:
Post a Comment