Subject: fread/fwrite problems in b18
From: [email-masked] (Bala Amavasai)

2 Jun 1997 20:59:41 -0700
Approved: [email-masked]
Distribution: cygnus
Message-ID: <Pine.SUN.3.96.970602154737.29633A-100000.cygnus.gnu-win32@mozart>
Mime-Version: 1.0
Content-Type: TEXT/PLAIN; charset=US-ASCII
X-Sender: bpa@mozart
Original-To: [email-masked]
Original-Sender: [email-masked]

Hi! I wonder if anyone can help.  I've written a short program to remove a
fix sized header (of 512 bytes) from a raw image file. However when I
compile it and run under gcc b18, I do not get the output I expect. That
is the output file size is always 30 bytes. The same code compiles and
works perfectly in Solaris 2.4 and Linux 2.0.27. The truncated version of
the code is fowarded below.

The computer which I'm using is a P100 with 16Mb RAM.

Another problem which I'm facing is that when I allocate a large array,
say 1000x1000 and when I read and write data to/off it, I get junk towards
1/4 way into the array. Once again the same code works very well in the
platforms above. Is there a problem with memory allocation? I'll send a
truncated piece of code later, unless the problem has been previously
logged. 

Thanks.

Regards,
Bala

========== Forwarded code starts here ================

/* Program to delete 512 byte headers of image files */

#include <stdio.h>

main(argc,argv)
int argc;
char **argv;
{
        FILE    *infile, *outfile;
        char    buf[BUFSIZ];
        int     n;

        if (argc<2)
        {
                fprintf(stderr,"Usage : %s <infile>\n",argv[0]);
                exit(1);
        }

        /* image file */
        if ((infile=fopen(argv[1],"r"))==NULL)
        {
                perror(argv[1]);
                exit(1);
        }

        /* create temp file */
        if ((outfile=fopen("outfile","w"))==NULL)
        {
                perror("outfile");
                exit(1);
        }

        /* Skip 512 byte header */
        fread(buf,sizeof(char),512,infile);

        /* Write rest of file to outfile */
        while((n=fread(buf,sizeof(char),BUFSIZ,infile))>0)
                fwrite(buf,sizeof(char),n,outfile);

        fclose(infile);
        fclose(outfile);
}

========== Code ends here ================

-
For help on using this list (especially unsubscribing), send a message to
"[email-masked]" with one line of text: "help".