Computer Forums

Member Login

Remember Me? Sign Up! | Forgot Password
 
Slogan
 
Computer Forums > Programmers Lounge > Programming Discussions » C Programming - just pause!
Closed Thread
Old 04-29-2006, 06:06 PM   #1 (permalink)
 
Ultra Techie

Join Date: Sep 2005

Posts: 638

tommyboy123x is on a distinguished road

Send a message via AIM to tommyboy123x
Default C Programming - just pause!

i was just quickly reading through an online guide to refresh my knowledge of C programming, and i just cant figure out why this program won't wait to display the results!

I'm sure there is something else wrong, but i can't debug it really, because i can't run it. I remember adding the following to the program, but that doesnt work.

Code:
getchar();
return 0;
here is my source

Code:
#include <stdio.h>

int main()
{
    int num;
    printf( "Please enter a Number: " );
    scanf( "%d", &num );
    if (num == 1234) {
            printf( "congratulations! \n" );
            printf( "you have guessed my number: ", num);
            }
    else {
         printf( "error:  Wrong Number\n");
         }
    getchar();
    return 0;
}
basic, but it doesn't wait to display the answer

what can i do to make this work properly (well maybe not properly, but pause at the end of the program before quiting)?

thanks!
__________________

Some real (as in actual) surveys that pay money!
tommyboy123x is offline  
Old 04-29-2006, 08:57 PM   #2 (permalink)
 
Software Developer

Join Date: Mar 2006

Location: Columbus, OH

Posts: 569

jaeusm is on a distinguished road

Default

try getch() instead of getchar().
jaeusm is offline  
Old 04-29-2006, 09:26 PM   #3 (permalink)
 
Super Techie

Join Date: May 2005

Posts: 479

furtivefelon

Default

you can also write system("pause"); before return 0;
__________________
lisp hacker
running: FreeBSD 5.4 - still learning
develop with: SBCL + emacs for lisp, Anjuta IDE +gcc for c, SPE for python..
browse with: opera
furtivefelon is offline  
Old 04-29-2006, 11:37 PM   #4 (permalink)
 
Ultra Techie

Join Date: Sep 2005

Posts: 638

tommyboy123x is on a distinguished road

Send a message via AIM to tommyboy123x
Default

i remember trying the system("PAUSE") but i put it after the return 0... makes more sence to put it before though

i think getch() is suiting my needs more, but system("PAUSE") will definatelly come in handy!!

thanks

edit: lol, yea, not really sure why i was putting in getchar()... i was thinking "fuction get character"... stupidity
__________________

Some real (as in actual) surveys that pay money!
tommyboy123x is offline  
 
Closed Thread

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On