By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,654 Members | 1,840 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,654 IT Pros & Developers. It's quick & easy.

when i am running the C prog after compile, it is not showing the result.

P: 3
#include <stdio.h>

void main()
int a;
printf("Enter value of a = ");
a = a + 10;
printf("The final value of a is %d",a);

when i am running this simple program it stops showing result. It executes only upto 'scanf'... After entering the 'a' value it is not showing the final result value.(i.e. 56, if a is entered 46) and i have to stop it forcefully from 'windows task manager'.

why it does happen and what is the solution?

Thank you.
Dec 11 '10 #1
Share this Question
Share on Google+
5 Replies

Expert Mod 5K+
P: 9,197
It probably does show your result. However, since you have no code to pause the program after the printf, your result is displayed for only a split-second.
Dec 11 '10 #2

Expert 100+
P: 2,400
It is common for stdout to be a buffered output. This means that characters written to stdout are held in an internal buffer until either a newline is written to stdout or fflush is called.

Terminate your format string with a newline.
Dec 12 '10 #3

P: 3
how can i pause the program to display result..?

i tried with different simple codes but the problem remains same. For exmple
i wrote the following code...

#include <stdio.h>

void main()
int i,j;

when i am running the code black screen appear for a moment and angain main (blue) screen appears..

what is the solution?

Thank you
Dec 12 '10 #4

P: 3
i terminated the format string with new line.. but it didnt work.
Dec 12 '10 #5

Expert 100+
P: 1,251
the simplest way is:

Expand|Select|Wrap|Line Numbers
  1. printf("Press enter to continue...");
  2. fflush(stdout);
  3. scanf("%*s");
Dec 12 '10 #6

Post your reply

Sign in to post your reply or Sign up for a free account.