Mail Archives: djgpp/1997/10/20/17:31:28
Marsel wrote in message <62fp85$nq4$1 AT power DOT ci DOT uv DOT es>...
> Hi djgpp users,
>
> I have writen this code
>
>#include <stdio.h>
>main()
>{
> char c;
> int n;
> printf("Write an integer: ");
> scanf("%d",&n);
> printf("Write a character: ");
> scanf("%c",&c);
> printf ("The integer is: %d and the character is: %d \n",n,c);
> }
>
>Why the secong scanf function does not wait until the caracter is
introduced
>?. the c variable always contain the caracter \010
This one always gets new C programmers. When you typed in the
integer, you probably also pressed the return key (i.e. newline). You
need to take care of reading that. Another scanf in there will do it:
int newline;
scanf("%d",&n);
scanf("%c",&newline);
etc...
----------------------------------------------------------------------
Donn Mielcarek donn AT srl DOT radix DOT net
----------------------------------------------------------------------
- Raw text -