🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.os.os2.programmer
Article #2163

Help with GCC (fread())

#2163
From: Wey Jing HO
Date: Mon, 28 Sep 1992 09:21
63 lines
2071 bytes
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);
   }
   else {
      number = fread(&image, sizeof(unsigned char), 12, fp_in); 
                                                /* read image file */
      if (number != 12){
         printf("\nnumber read = %3d.\nfread error!\n", number);
         printf("ferror() report: %3d\n", ferror(fp_in));
         exit(ERROR);
      }
      else { /* everything is OK */
         printf("\nOK\n");
         exit(OK);
      }
   }
}


/* This is how I compile it. No errors are reported. */
gcc -c test.c


/* This is how I link it */
link386 test.obj
/* Accept everything after this as defaulted */


/* This is the output from the test program. */
number read =   0.
fread error!
ferror() report:   0

/* Thanks for your help. */
-- 
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>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.092116.29086@monu6.cc.monash.edu.au>
Path: arc1-ca.pugleaf.net!sparky!uunet!munnari.oz.au!bruce.cs.monash.edu.au!monu6!sci240s

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: Help with GCC (fread())
Message-ID: <1992Sep28.092116.29086@monu6.cc.monash.edu.au>
Organization: Monash University, Melb., Australia.
Date: Mon, 28 Sep 1992 09:21:16 GMT
Lines: 63