can i use statements like:
int num;
fread(&num,sizeof(num),1,stdin);
fwrite(&num,sizeof(num),1,stdout);

i tried this and debugged the code the variable is having the correct value.
but that is not getting displayed.


can't i use stdin , stdout in fread and fwrite.

I cannot say what the problem is without more code to test with, but it might be that your runtime is not flushing stdout. Try printing a '\n' character or calling fflush(stdout) after the fwrite() to force a flush.

The read should work, but the write doesn't because you are trying to write binary data to the console screen. The number will have to be converted to ascii readable characters first.

char buf[20];
sprintf(buf,"%d", num);
fwrite(buf,strlen(buf),1,stdout); // but why?? this is the same as printf()

Considering ascii data, fwrite will write sizeof(num) characters to the standard ouput. Characters order depends on machine type - little endian or big endian.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.