Programming Wont Be Fun Till I Know This

This is a discussion on Programming Wont Be Fun Till I Know This within the C++ Programming forums, part of the General Programming Boards category; ok I am using codewarrior on a macintosh and I NEED to know how to use time in my programs. ...

  1. #1
    Unregistered
    Guest

    Angry Programming Wont Be Fun Till I Know This

    ok I am using codewarrior on a macintosh and I NEED to know how to use time in my programs. If I want something to pause, I use huge blank for loops and that varies from machine to machine AND it is inaccurate and my screen does some wierd blinking thing when it works through the for loops. Is there a time function. I looked through time.h and I couldnt find anything. PLEASE HELP ME

    ALykz

  2. #2
    Registered User *pointer's Avatar
    Join Date
    Oct 2001
    Posts
    74
    The easiest way to pause a program is getchar(); Like so:
    Code:
    .
    .
    .
    while(1){
        cout<<"Something"<<endl;
        getchar();
    }
    That will stop the program after every iteration of the loop until you hit a key. Be sure to include stdio.h though
    pointer = NULL

  3. #3
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,417
    > Is there a time function.
    Well you should have time and difftime

    This should be a portable delay - but it will run the CPU at 100% doing it.
    Code:
    void wait ( int seconds ) {
        time_t now = time(NULL);
        while ( difftime(time(NULL),now) < seconds ) {
        }
    }
    
    int main ( ) {
        wait( 3 );
        return 0;
    }
    Most systems provide something like delay, sleep or Sleep, but all these are OS specific. They do however usually suspend your program to allow the OS to do other things.

  4. #4
    left crog... back when? incognito's Avatar
    Join Date
    Oct 2001
    Posts
    1,427
    you could try........
    cout<<"enter number";
    cin>>n;
    25.5
    int x;
    cin>>x;


    will cause the program to pause until x is entered, be careful though if you let's say 25.5 before it you have to declare that as a float(or something along those lines), because if 25.5 is an interger after 25. the program will close because it assumes that 5 is x thus closing before letting you achieve your purpose.
    Last edited by incognito; 11-17-2001 at 02:10 PM.
    There are some real morons in this world please do not become one of them, do not become a victim of moronitis. PROGRAMMING IS THE FUTURE...THE FUTURE IS NOW!!!!!!!!!

    "...The only real game I thank in the world is baseball..." --Babe Ruth

    "Life is beautiful"-Don Corleone right before he died.

    "The expert on anything was once a beginner" -Baseball poster I own.


    Left cprog on 1-3-2005. Don't know when I am coming back. Thanks to those who helped me over the years.

  5. #5
    Sayeh
    Guest
    First of all-- we're talking Macintosh. Using silly 'cout' delays is stupid, and is a DOS way of thinking about things.

    The Macintosh has a much more sophisticated GUI than any other computer out there. As such, it comes with tons of 'Inside Macintosh' guidelines about how to write code for it.

    If you are trying to write programs on the Mac without getting yourself 'Inside Macintosh'-- you are screwed. Buy some books, it will help you.

    Pointers are handled much more intelligently, as well as handles, and other memory mechanisms on the Mac. Something Microsoft never mastered, and is a foreign concept to most PC developers.

    Now-- to answer your question--

    If you want to cause a pause in program operation, try using either a) the Time Manager, or b) the Delay() procedure.

    Be aware, that while you are hogging time, other applications might not be getting time, so you might also have to call A function while you are delayed that will give other applications time-- This is cooperative multitasking.

    if you are talking O/SX, then you are probably true multitasking and don't have to worry about sharing time, the Process Manager will do that for you.

    enjoy.

  6. #6
    left crog... back when? incognito's Avatar
    Join Date
    Oct 2001
    Posts
    1,427

    Well Sorrrrrrrrrrryyyyyy!!!!!

    First of all buddy I forgot that he was using a Mac second of all cout is not the one causing the delay just in case you didn't understand me, and I didn't me it for that I made a mistake I was indeed talking about if he was making a program, that the dos windows shut down before he could view his results, I mean that he make the windows from shutting down, by using cin>> to pause it.
    There are some real morons in this world please do not become one of them, do not become a victim of moronitis. PROGRAMMING IS THE FUTURE...THE FUTURE IS NOW!!!!!!!!!

    "...The only real game I thank in the world is baseball..." --Babe Ruth

    "Life is beautiful"-Don Corleone right before he died.

    "The expert on anything was once a beginner" -Baseball poster I own.


    Left cprog on 1-3-2005. Don't know when I am coming back. Thanks to those who helped me over the years.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Auto Calling Derived Fun
    By Arlenik in forum C++ Programming
    Replies: 27
    Last Post: 06-02-2008, 11:17 AM
  2. read characters till white space
    By ashok449 in forum C Programming
    Replies: 2
    Last Post: 03-08-2008, 02:56 AM
  3. Pointer fun!!
    By errno in forum A Brief History of Cprogramming.com
    Replies: 26
    Last Post: 06-24-2004, 05:26 PM
  4. Fun Learning a New Language
    By UnregdRegd in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 09-30-2003, 10:03 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21