This is my Code [Note: I am using Eclipse for C/C++ on Windows Platform]
#include <stdio.h>
#include<stdlib.h>
int main(void) {
int num;
printf("Enter a number:\n");
scanf("%d",&num);
if(num%2==0)
printf("Number is Even");
else
printf("Number is Odd");
return EXIT_SUCCESS;
}
Here I have to enter an Integer first only then printf is called... I want to call printf first before I enter an Integer...What am I doing wrong here?
for example this is the output that I get
6
Enter a number:
Number is Even
and expected output is
Enter a number:
6
Number is Even
scanf
is not returning, or that the final call toprintf
is not producing output?stdin/stdout
as an "interactive device", it will be fully buffered. In this case, output may be buffered until a call tofflush(stdout)
(or one of a number of other function calls) is encountered.printf("Enter a number:\n");fflush(stdout);
printf()
appearing when expected?" since you've not produced any evidence that the calls are not made but only that you don't see the output you expect.