fscanf bug?

Ron Stanonik stanonik at nprdc.navy.mil
Thu Jul 20 17:00:00 AEST 1989


Or maybe it's a feature?  But it was news to me.

I believe we've encountered an fscanf bug in sunos4.0.1 on sun4's, sun3's,
and sun386i's.

The apparent bug is that given a control string of "%c", fscanf returns 0,
rather than EOF on encountering the end of file.

Here's a sample program:
#include <stdio.h>

main()
{
	int i;
	char c;

	for (i = 5; i > 0; i--) {
		printf("cnt=%d\n", fscanf(stdin, "%c", &c));
		printf("%x\n", c);
	}
}

Here's a sample file:
ab

Here's the result:
arctic[244] t < a
cnt=1
31
cnt=1
33
cnt=1
a
cnt=0
a
cnt=0
a

Back in sunos3.5 days, the 0 cnt's would be -1 (ie, EOF), as expected.

Ron Stanonik
stanonik at nprdc.navy.mil



More information about the Comp.sys.sun mailing list