FILE I/O: fread() fails for GCC(Cygnus & DJ's) and TC++

Rich Kucera
Fri Apr 25 07:01:00 GMT 1997

     On Linux & MPRAS,  the sample program listed below manages to
     read through all thirty POINT structures with no problems. 
     The program won't port however,  because it appears that
     any DOS-based (FAT?) compiler (Cygnus GCC & DJ's GCC and Turbo C),
     creates a binary that quits halfway through the data(15 points read).
     I'm probably missing something about file I/O,  or it
     could be some low-level file I/O problem.  I don't know,  help.
     Visual Basic had no problem with this data.   The gnu-win32 utilities
     such as HEAD.EXE ALSO QUIT after getting about 95 bytes into this
     I checked the representation for signed short for every compiler
     tested and they all use 2 BYTES,  so no problem there?  I used
     There should be 180 bytes composing 30 POINT structures.

The data follows here and is attached in raw form in a zip file:
begin 640 data.pnt

M 0 J"(7^ @ 2"'?^ 0 *"''^ @#[!VC^! #T!V#^ 0#P!UK^ 0#L!T_^ 

M!T?^ @#G!T3^ @#B!SS^ 0#@!SC^ @#A!S3^ 0#=!R_^ 0#<!RG^ @#:!R7^

M 0#6!QK^ 
@#3!P[^ 0#-!PC^ @#,!P7^! #,!P'^ @#'!_O] @##!_K] @"T

M!^O] 0"N!^/] 
0"G!]O]!0"A!]/] 0"@!]/] @"<!]7] @"6!]+] 0"5!]/]



     Here is the test program(also attached):

#include <stdio.h>

typedef struct POINT {
  signed short CODE, LAT, LON;   

main(argc, argv)
int argc;    
char *argv[];

  int num_points_read;
  if( ( INFILE = fopen( "data.pnt", "r" ) ) == (FILE *) NULL ) {
    printf("Can't open %s.\n", "data.pnt");
    exit( 2 ); 
  num_points_read = 0;

  while ( fread(&NEWPOINT, sizeof(POINT), 1, INFILE) == 1 ) {

  }                 /* while () */

  printf("\n%d points read from %s\n\n",

  if (INFILE != NULL) {    fclose(INFILE); }
    exit( 0 ); 
     /* THE END */
Unknown data type
Unknown data type

-------------- next part --------------
A non-text attachment was scrubbed...
Type: application/zip
Size: 265 bytes
Desc: not available
URL: <>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: gena.c
Type: text/x-c
Size: 639 bytes
Desc: not available
URL: <>

More information about the Cygwin mailing list