[comp.sys.amiga] Lattice C

jeo@mentor.cc.purdue.edu (Richard Napier) (12/19/89)

 I need help with a problem I have run into with Lattice C for the Amiga.
 I purchased the compiler in July and I am having trouble with the scanf()
 function.  Here is my code.

 #include <stdio.h>
 main()
{
   int num1;
   char chr1;

   printf("Enter a number: ");
   scanf("%d",&num1);
   printf("\nEnter a character : ");
   scanf("\n%c",&chr1);
   printf("\n>> %c <<");
}
According to a C book I have the \n before the %c in the scanf() should
make the scanf ignore the \n that the previous scanf leaves behind.  I
tried this onthe UNIX system at Purdue University, and it worked fine.
I then tried it on the Amiga, compiled it with Lattice C, and it doesn't
work.  The \n before the %c in the second scanf command is ignored.
How can I get around this, someone told me that it had something to do
with the keyboard buffer.  Can I do something else that will work the 
same??? 
                    Can someone from Lattice help??

                    Thank You,
                                    Tony Hutson

new@udel.edu (Darren New) (12/20/89)

In article <6035@mentor.cc.purdue.edu> jeo@mentor.cc.purdue.edu (Richard Napier) writes:
>   scanf("\n%c",&chr1);
>According to a C book I have the \n before the %c in the scanf() should
>make the scanf ignore the \n that the previous scanf leaves behind.  I
>tried this onthe UNIX system at Purdue University, and it worked fine.
>I then tried it on the Amiga, compiled it with Lattice C, and it doesn't
>work.  The \n before the %c in the second scanf command is ignored.

I had this same problem.  The problem is that ANSI differs from Unix in
this respect.  Also, the Lattice manual documents it for the wrong version.
Seems they forgot to change it when upgrading the library to ANSI.
In reality ALL WHITESPACE IN A SCANF SPECIFICATION IS IGNORED!
Your easiest solution around this bug-like feature (:-) is to
simply scanf("%*c%c",&chr1) or {getchar(); scanf("%c", &chr1);}.
(Check my syntax on that... I don't do stdio very much).
Good luck, and may your manuals always be up to date. -- Darren

fmcphers@VTTCF.CC.VT.EDU (Frank McPherson) (12/19/90)

Recently, this went over the net:
-} - In the current version, and with a bit faster Amiga (e.g. 020 and up), SAS
-}   C is currently the better choice (Hi Ralph!) if you need a high quality C 
-}   Compiler. Of course, you pay for it (are you a student ? They give 50%    
-}   rebate [I think]!) Using my A3000/25, the compiler runs quite fast, though
-}   I wouldn't want to use it on my A1000... (never tried it yet).

I'm especially interested in the 50 % rebate idea.  IS there any kind of 
discount given to students by SAS for thier C compiler?  I've been hemming and
hawing about getting SAS for a while now, but I keep managing to convince 
myself to wait longer.  If I could get such a nice discount, it would 
help immensely. 

Thanks in advance for all replies, which should, BTW, be via EMAIL, since I'm
going to be at home till after christmas and won't be able to read the 
comp.sys.amiga groups till then.  Thanks!

-- Frank McPherson                  INTERNET: fmcphers@vttcf.cc.vt.edu --