delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/1997/06/02/20:59:41

From: B DOT Amavasai AT sheffield DOT ac DOT uk (Bala Amavasai)
Subject: fread/fwrite problems in b18
2 Jun 1997 20:59:41 -0700 :
Approved: cygnus DOT gnu-win32 AT cygnus DOT com
Distribution: cygnus
Message-ID: <Pine.SUN.3.96.970602154737.29633A-100000.cygnus.gnu-win32@mozart>
Mime-Version: 1.0
X-Sender: bpa AT mozart
Original-To: gnu-win32 AT cygnus DOT com
Original-Sender: owner-gnu-win32 AT cygnus DOT com

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
"gnu-win32-request AT cygnus DOT com" with one line of text: "help".

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019