gunzip complains "Unexpected End-of-file" when C prog's output is fed to it in bash
Hi,
I have a C program (a.out) which outputs a file in the stdout. Then I pipe the output of this C program to gunzip to decompress the data. The data output by the C program was previously compressed with gzip. My shell script looks like this:
#!/bin/sh
./a.out | gunzip -dc > new_file
But, when I try to run this script from command line, I get the following error:
gunzip: stdin: unexpected end of file
In my C program, I output the file with:
fwrite(array, sizeof(unsigned chat), size, stdout);
fflush(stdout);
fclose(stdout);
I don't understand why still gunzip complains about unexpected end of file. My search for the answer revealed that the file pointer to which the C program writes data (in this case stdout), must be closed explicitly. I have already done so... Can anyone please put some light on what I might be doing wrong?
--Thanks in advance.
|