Jump to content

Wait or sleep command??

- - - - -

  • Please log in to reply
5 replies to this topic

#1
bbqroast

bbqroast

    Codecall Addict

  • Members
  • PipPipPipPipPipPipPip
  • 535 posts
  • Location:/etc/passwd
One of the problems i've been encontering recently is that my C/C++ programs close before you can read anything... I have been searching around for a wait/sleep command (yet all i get is people moaning about how tired they are). So anyone know how to use them??

Here is a older code i have that would be much better if it had a wait/sleep command...

#include<stdio.h>

main()

{

int a;

int b;

int c;

printf("Enter the first number:");

scanf("%d",&a);

printf("Enter the second number:");

scanf("%d",&b);

c = a*b;

printf("%d ",a);

printf("X ");

printf("%d ",b);

printf("equals ");

printf("%d ",c);

return 0;

}


#2
tate

tate

    Learning Programmer

  • Members
  • PipPipPip
  • 90 posts
A quick google search for "c sleep" presented The GNU C Library
hope it helps.
twas brillig

#3
Flying Dutchman

Flying Dutchman

    Programming God

  • Members
  • PipPipPipPipPipPipPip
  • 889 posts
  • Location:::1
There are several ways to "resolve" this issue:
    if you're on Windows, you could use system("pause");
    in C++ you could include iostream header and use std::cin.ignore(); and std::cin.get(); (place those before return 0; )
    also, you could run your programs from console (cmd on Windows and Terminal on Linux)

A conclusion is where you got tired of thinking.
#define class struct    // All is public.

#4
dargueta

dargueta

    Writes binary right handed and hex left handed

  • Moderators
  • 4,717 posts
  • Programming Language:C, Java, C++, PHP, Python, Perl, Assembly, Bash, Others
  • Learning:JavaScript
Do not use system() if you can help it. It's error-prone and platform-specific. I suggest you use getc(stdin).
sudo rm -rf /

#5
entity18

entity18

    Newbie

  • Members
  • Pip
  • 3 posts
This will work for you!





[SIZE="2"]#include<stdio.h>

main()

{

int a;

int b;

int c;

printf("Enter the first number:");

scanf("%d",&a);

printf("Enter the second number:");

scanf("%d",&b);

c = a*b;

printf("%d ",a);

printf("X ");

printf("%d ",b);

printf("equals ");

printf("%d ",c);

getch();                 /*  ----->    getch()  <----- this means it will take any character before preciding to next step */

}[/SIZE]

Edited by entity18, 06 July 2010 - 11:12 PM.


#6
dargueta

dargueta

    Writes binary right handed and hex left handed

  • Moderators
  • 4,717 posts
  • Programming Language:C, Java, C++, PHP, Python, Perl, Assembly, Bash, Others
  • Learning:JavaScript
Entity, that'll work too. One thing, though: when posting code, please use the appropriate code tags so we can read it more easily. Paste in your code, highlight it, then click on the # button. VoilĂ ! Readable code. :)
sudo rm -rf /




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users