[comp.sys.mac.misc] MPW C 3.1 scanf problem

David_Anthony_Guevara@cup.portal.com (01/22/91)

I have a (hopefully) real simple problem.  I am using MPW C 3.1
to do some programming for a C class.  What I want to do is to prompt
the user and leave the cursor at the end of the prompt line.  My problem
is that scanf will not read the input if the cursor is at the end of the
prompt line.  I have to start on a newline for scanf to get the value.
Example code:

#include <stdio.h>
main()
{
     int input1;

     printf("Input an integer value: ");  /* cursor is at end of line */
     scanf("%d",&input1);
     printf("input1 = %d\n",input1);
}

If I put a newline in after the prompt, the scanf works.  If I leave the
code as stated above, I'll get some garbage.  I'm building this under
MPW as a tool.  Is this a known problem/undocumented feature of MPW C?
I've compiled the same code under Think C 4.02 and Turbo C with no problem.
E-mail me your responses.  I'm sure this is too elementary to waste on the
net.  As always, I will summarize to the net if there is sufficient interest.

	Dave Guevara,
	Internet:  David_Anthony_Guevara@cup.portal.com

ml27192@uxa.cso.uiuc.edu (lanett mark) (01/23/91)

David_Anthony_Guevara@cup.portal.com writes:

>I have a (hopefully) real simple problem.  I am using MPW C 3.1
>to do some programming for a C class.  What I want to do is to prompt
>the user and leave the cursor at the end of the prompt line.  My problem
>is that scanf will not read the input if the cursor is at the end of the
>prompt line.  I have to start on a newline for scanf to get the value.
[example code deleted]

MPW Buffers lines, and a scanf or anything will read in _everything_ on the
cusor's line. You must do the newline before.

Mark Lanett