Computer ForumsComputers  

Go Back   Computer Forums > Programmers Lounge > Programming Discussions

Reply
 
LinkBack Thread Tools Display Modes
Old 04-29-2006, 06:06 PM   #1 (permalink)
Ultra Techie
 
Join Date: Sep 2005
Posts: 625
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!
__________________
Life is good with SparkCash =)
tommyboy123x is offline   Reply With Quote
Old 04-29-2006, 08:57 PM   #2 (permalink)
Software Developer
 
Join Date: Mar 2006
Location: Columbus, OH
Posts: 492
Default

try getch() instead of getchar().
jaeusm is offline   Reply With Quote
Old 04-29-2006, 09:26 PM   #3 (permalink)
Super Techie
 
Join Date: May 2005
Posts: 479
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   Reply With Quote
Old 04-29-2006, 11:37 PM   #4 (permalink)
Ultra Techie
 
Join Date: Sep 2005
Posts: 625
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
__________________
Life is good with SparkCash =)
tommyboy123x is offline   Reply With Quote
Reply

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



All times are GMT -5. The time now is 07:52 PM.


Powered by vBulletin® Version 3.7.1
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.1.0