Unix problem or C problem?

David Goodenough dg at lakart.UUCP
Fri Jan 20 02:10:05 AEST 1989


>From article <245 at ibd.BRL.MIL>, by heilpern at ibd.BRL.MIL (Mark A. Heilpern ):
> 	When running a program with the following code:
> 
> 	while (fscanf(input,"%d",stars)!=EOF)
>	{
> 		fprintf(stderr,"OK to this point.\n");
> 		fprintf(output,"%4d |",lines++);
> 		stars /= 50;
> 		for (count = 0; count <= stars; count++)
> 			fprintf(output,"*");
> 		fprintf(output,"\n");
> 	}
> 
> 	I get the following error message, NOT put out from my program:

Try fscanf(input, "%d", &stars) 
			^
			^ TO ASSIGN INTO AN int, scanf() NEEDS THE ADDRESS

As an aside, I generally avoid testing scanf() values against EOF. scanf()
returns the number of successful assignments (1 in this case), so you may
be a lot safer saying:

	while (fscanf(input, "%d", &stars) == 1)
-- 
	dg at lakart.UUCP - David Goodenough		+---+
						IHS	| +-+-+
	....... !harvard!xait!lakart!dg			+-+-+ |
AKA:	dg%lakart.uucp at xait.xerox.com		  	  +---+



More information about the Comp.unix.wizards mailing list