Article View: comp.os.os2.programmer
Article #2164Re: Help with GCC (fread())
From: Wey Jing HO
Date: Mon, 28 Sep 1992 10:06
Date: Mon, 28 Sep 1992 10:06
40 lines
1822 bytes
1822 bytes
In <1992Sep28.092116.29086@monu6.cc.monash.edu.au> sci240s@monu6.cc.monash.edu.au (Wey Jing HO) writes:
I've just found the problem. Replacing the line where the file is opened with
"r+b" to "rb" solves the problem BUT why shouldn't "r+b" work correctly?
If I read all the C books I have, "r+b" should work almost similarly to "rb"
except that "r+b" allows updating. So, is this a bug in GCC?
>In trying to use GCC Version 2 for OS/2, I have the following problem:
>I am having problem writing a program that read in data in binary format
>into an array. I've included the source as below with all the instructions
>I used to compile and link it (with link386). Please help.
>/* Start of test program */
>#include <stdio.h>
>#include <stdlib.h>
>#define ERROR -1
>#define OK 1
>int main(){
> FILE *fp_in;
> unsigned char image[512];
> int number;
> if ((fp_in = fopen("test.img", "r+b")) == NULL){ /* open image file */
> printf("\nfopen() failed.\n");
> fflush(stdout);
> exit(ERROR);
* Remainder deleted.
--
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>Wey Jing Ho Tel: 61-3-573-2567 E-mail : sci240s@monu6.cc.monash.edu.au<
>Physics Dept., Monash University ( Caulfield Campus ), Melbourne, AUSTRALIA<
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Technical Details
Message-ID:
<1992Sep28.100655.2758@monu6.cc.monash.edu.au>Path:
arc1-ca.pugleaf.net!sparky!uunet!munnari.oz.au!bruce.cs.monash.edu.au!monu6!sci240sReferences:
<1992Sep28.092116.29086@monu6.cc.monash.edu.au>Show Full Headers
Complete Article Headers
Newsgroups: comp.os.os2.programmer Path: arc1-ca.pugleaf.net!sparky!uunet!munnari.oz.au!bruce.cs.monash.edu.au!monu6!sci240s From: sci240s@monu6.cc.monash.edu.au (Wey Jing HO) Subject: Re: Help with GCC (fread()) Message-ID: <1992Sep28.100655.2758@monu6.cc.monash.edu.au> Organization: Monash University, Melb., Australia. References: <1992Sep28.092116.29086@monu6.cc.monash.edu.au> Date: Mon, 28 Sep 1992 10:06:55 GMT Lines: 40