Originally Posted by
DevSun
Oh great thanks! And for future reference, whenever I have a scanf(), do I put a getchar(); after it?
The greatest thing about programming is that you can see for yourself.
Code:
#include <stdio.h>
int main(void)
{
int x;
printf("Enter an integer: ");
scanf("%d",&x);
printf("You entered %d\n",x);
getchar(); // <--- does it work as you expect?
return 0;
}
Code:
#include <stdio.h>
int main(void)
{
char x;
printf("Enter a character: ");
scanf("%c",&x);
printf("You entered %c\n",x);
getchar(); // <--- does it work as you expect?
return 0;
}
Code:
#include <stdio.h>
int main(void)
{
float x;
printf("Enter a floating point number: ");
scanf("%f",&x);
printf("You entered %f\n",x);
getchar(); // <--- does it work as you expect?
return 0;
}