[comp.sys.mac] ThinkC *scanf

adiseker@deimos.ads.com (Andrew Diseker) (01/12/90)

	Some time back, someone mentioned they were having problems with
scanf() in the ThinkC 4.0 ANSI library.  I copied someone (else's?)
response which contained a 2-line patch to scanf.c.  I made that fix, but
I'm still having a devil of a time trying to use the scanf family.  I
have a text file which contains floating point numbers, which I am trying to
read in to separate floats.  The following is the code I'm using to test.

#include <stdio.h>
main() {
	float	a = 1.2, b = 2.1, c, d;
	FILE	*fptr;
	char	*fileName = "sam";
	char	buffer[100];	
	
	fptr = fopen(fileName, "w+" );
	fprintf(fptr, "%f %f", a, b, c, d );
	
	fclose(fptr);
	fptr = NULL;

	fptr = fopen(fileName, "r+" );

/*  this was the first way I tried
	fscanf( fptr, "%f %f", &c, &d );	*/

/*	this was the second way I tried		*/
	fgets( buffer, 100, fptr );
	printf("%s from file\n", buffer );
	sscanf( buffer, "%f %f", &c, &d );
	
	printf( "a = %f, b = %f, c = %f, d = %f\n", a, b, c, d );
	
	fclose( fptr );
	
}


	Both the commented-out fscanf and the sscanf had the same effect:
a remained unchanged, b got trashed, c and d were set to garbage.  Has 
anyone fixed this, and are source code patches available?  This is holding
up some critical work that I'd just as soon be done with, so I can go on
to even more critical work %*(  E-mail replies requested, but I do try to
keep up on this group.

			Ocheyn Spaceeba!