0

I know C++, but I'm trying to learn C. Anyways, what am I doing wrong here. If I delete the line with 'scanf', it will compile so obviously I'm doing something wrong there. Anyways...

#include <stdio.h>


int main() {

	int x;

	printf("enter a number\n");
	scanf("%d", &x);
	printf("Your number is: %d\n", x);
	return 0;
}
3
Contributors
4
Replies
6
Views
6 Years
Discussion Span
Last Post by RideFire
0

I found my error but I have a question about it. My executable is blank until I enter a number. Once, I enter a number then all my printf's show up declaring enter a number and your number is _. How do I fix this? This is what my output looks like.

6
enter a number
Your number is: 6
0

Im using Code::Blocks and run well! IDK you! Try another compiler!

0

After googling in eclipse forums, this is a known bug within the program. The fix is adding this under main.

setvbuf(stdout, NULL, _IONBF, 0);
setvbuf(stderr, NULL, _IONBF, 0);
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.