Willie Trombone
Honorary Master
- Joined
- Jul 18, 2008
- Messages
- 60,038
Hi, I'm not a C fundi and I've googled a bit but haven't come up with an answer...
My son is studying at the mo and doing a programming module at uni - they're using C. What I can't yet answer is why the
statement is required in the code below:
The code fires and appears to produce the same result with or without it... is there a reason it's included? Is this perhaps a 'best practice' situation where you want to be sure there isn't a buffer set? Any help is appreciated!
My son is studying at the mo and doing a programming module at uni - they're using C. What I can't yet answer is why the
Code:
setbuf(stdout, 0);
Code:
#include <stdio.h>
int main () {
int num1, num2, ans;
[B] //setbuf(stdout, 0);[/B]
printf("Please enter the first integer:\n");
scanf("%d",&num1);
printf("Please enter the second integer:\n");
scanf("%d",&num2);
ans=num1+num2;
printf ("\n%d + %d = %d", num1, num2, ans);
return 0;
}
The code fires and appears to produce the same result with or without it... is there a reason it's included? Is this perhaps a 'best practice' situation where you want to be sure there isn't a buffer set? Any help is appreciated!