Beginning C question.

Wade Guthrie evil at arcturus.uucp
Thu Jul 26 07:34:47 AEST 1990


Wally Sze writes:
> [...] My
> compiler uses 16-bit ints, and I need to read some 32bit long ints
> from disk. 

Try fread().  For example:

	#include <stdio.h>

	...

	FILE	*file, *fopen();
	long	foo;
	int	items = 1, actual_num;

	...

	if( (file = fopen(...)) == NULL)
		/* some error handling here */
	if((actual_num = fread(&foo, sizeof(foo), items, file)) != items)
		fprintf(stderr, "fread only read %d items", actual_num);

In the scope of a prototype of fread (to allow for the proper cast
of &foo) will read a single long into foo.
-- 
Wade Guthrie (evil at arcturus.UUCP)    | "He gasped in terror at what sounded
Rockwell International; Anaheim, CA  | like a man trying to gargle while
My opinions, not my employer's.      | fighting off a pack of wolves"
                                     |                Hitchhiker's Guide



More information about the Comp.lang.c mailing list