Hi, new to the C world, looking for some basic elementary help

Hi, I've recently taken this computer course for one of the requirements for my university program. I was wondering if some of you could help field a few questions. I was playing around with Dev C++, and was writing a very basic program that printed some info, and required some data input. However I was wondering, at the end of my program it terminates almost immediately and I am unable to view the resultant info. How can I make it so the program terminates only when i press a key on the keyboard? Another question is field width, lets say i want to specify the field width for a double value such as %5.2lf.....i understand that there will be two values after the decimal because of the .2, but what about the 5...does that mean i will have 5 places of value infront of the decimal? What if I dont require that many spaces, such as a value of 34.23?

Also we are programming in C, if that was not clear.


  • crap, just saw the beginner subforum...srry!
  • Im not sure but just try to put a function getchar() after closing your function main().

    Using of floating value for example 5.23, try to use the %.2f. it means you are going to display two-decimal place value.
    Correct me if im wrong...thanx
  • Don't use getchar(), instead use getch() as last statement of your main. getchar() echoes the read byte from keyboard to screen.
  • Do -not- use getch(), it isn't standard C and will not work in C programs.

    getchar() is the best way.
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!