Sun OS 4 scanf problem

Glenn P. Davis davis at handies.ucar.edu
Thu Jan 19 17:19:33 AEST 1989


/*
 * Hi.
 * 
 * The following program demonstrates a problem with
 * the scanf family of functions under SunOS 4.
 * 
 * The problem has been observed on a sun3 and on a sun4 running Sun OS 4.O.1.
 * The problem was has been observed with fscanf as well as sscanf.
 * 
 * Thanks.
 * 
 * Glenn P. Davis
 * UCAR / Unidata
 * PO Box 3000                   1685 38th St.
 * Boulder, CO 80307-3000        Boulder, CO  80301
 * 
 * (303) 497 8643
 */

char string[] = "00235 01162 18019 85514 05980 24531 70009 14360 26042 50550 28748 26083" ;

main()
{
	int cnt ;
	float h, t, td, dir, spd ;

	printf("Should scan as:\n") ;
	printf("cnt: 5; 235.000000 11.000000 62.000000 180.000000 19.000000\n") ;
	cnt = sscanf( string,"%*2s%3f %3f%2f %3f%2f",
		&h, &t, &td, &dir, &spd) ;

	printf("In fact scans as:\n") ;
	printf( "cnt: %d; %f %f %f %f %f\n",
		cnt, h, t, td, dir, spd) ;
}

/*
 *  Workaround:
 *    Change:
	cnt = sscanf( string,"%*2s%3f %3f%2f %3f%2f",
		&h, &t, &td, &dir, &spd) ;
 *    To: 
	cnt = sscanf( string,"%*2s%f %3f%f %3f%f",
		&h, &t, &td, &dir, &spd) ;
 */



More information about the Comp.sys.sun mailing list