So i am providing a file content to the c program in Command prompt like this. eg- TYPE "FileName" | CProgram.exe . Type command takes the content of file and provides it to my cporgram.exe
Code::
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
# define CACHE 102400
int main(int argc, char* argv[])
{
    
    char *buf = malloc(CACHE * sizeof(char));
    FILE* f = fopen("out.txt", "wb");
    size_t bytesread;
    while(bytesread = fread(buf, sizeof(char), CACHE, stdin))
    {
        printf("bytes read = %zu\n", bytesread);
        fwrite(buf, bytesread, 1, f);
    }
    
    return 0;
}
Im providing a image file as an input. The problem is that the program terminates after reading few bytes. But if i provide a text file it seems to work fine. What should i change so my program can read the piped image file content properly
 
     
    