GIDForums  

Go Back   GIDForums > Computer Programming Forums > C++ Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 29-Dec-2006, 11:29
killzone killzone is offline
Junior Member
 
Join Date: Nov 2006
Posts: 66
killzone is an unknown quantity at this point

System("PAUSE") equivalent unix


is there a system("PAUSE") equivalent in UNIX
  #2  
Old 29-Dec-2006, 11:43
davekw7x davekw7x is offline
Outstanding Member
 
Join Date: Feb 2004
Location: Left Coast, USA
Posts: 5,311
davekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to behold

Re: System("PAUSE") equivalent unix


Quote:
Originally Posted by killzone
is there a system("PAUSE") equivalent in UNIX
Not unless you have an executable program named "PAUSE" on your system that does the same thing as the built-in "PAUSE" windows command. See footnote.

I hardly ever need something like system("PAUSE") for my Windows applications or my Linux applications, but I would probably change the functionality slightly so that I could use standard library functions on both and do something like this:

CPP / C++ / C Code:
#include <stdio.h>

int main()
{
    int i;

    for (i = 0; i < 3; i++) {
        printf("i = %d\n", i);
        printf("Press 'Enter' to continue: ... ");
        while ( getchar() != '\n')
            ;
    }
    printf("\n\n");
    printf("Ttttthat's all, folks\n");
    printf("Press 'Enter' to exit the program (ironic, isn't it?) ...");
    while (getchar() != '\n')
        ;
    printf("\n\n");
    printf("Ttttthat's really all!\n");
    return 0;
}

Works for me on Windows and on Linux with no changes to the source code.

Code:
i = 0 Press 'Enter' to continue: ... i = 1 Press 'Enter' to continue: ... i = 2 Press 'Enter' to continue: ... Ttttthat's all, folks Press 'Enter' to exit the program (ironic, isn't it?) ... Ttttthat's really all!

Note that this is a valid C program and also a valid C++ program, but C++ programmers would probably use cout<< instead of printf, and cin.get() instead of getchar().

Regards,

Dave

Footnote: The Windows built-in command "PAUSE" is kind of like printing the message and then executing getch() and throwing away the char. I have never seen a Linux system with a "PAUSE" system command, but it is undoubtedly possible to implement such a thing. (I have also never seen a C/C++ compiler distribution that has getch(), unless you use ncurses, which is typically available on Linux systems. Since ncurses is not necessarily included with Linux distributions, and is often not available with Windows C compilers, I usually don't use ncurses unless I really, really need some special screen functionality but don't need a full-fledged GUI program.

Since my goal is portability across platforms, I (usually) avoid using system commands (or C library functions) for which I am not prepared to supply the source code so that the application can be re-compiled for virtually any platform.
  #3  
Old 02-Jan-2007, 01:32
WaltP's Avatar
WaltP WaltP is offline
Outstanding Member
 
Join Date: Feb 2004
Location: Midwest US
Posts: 3,373
WaltP is a name known to allWaltP is a name known to allWaltP is a name known to allWaltP is a name known to allWaltP is a name known to allWaltP is a name known to all

Re: System("PAUSE") equivalent unix


Also, check this info to see why you don't want to use system("PAUSE") in the first place -- and what to replace it with...
__________________

The 3 Laws of the Procrastination Society:
1) Never do today that which can be put off until tomorrow
2) Tomorrow never comes
 
 

Recent GIDBlogNot selected for officer school by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Copy/Paste from Excel into an FL_Input field UNIX app doesn't work ? jl_nicoue FLTK Forum 1 26-Jul-2006 13:15
Reading Excel Sheets on Unix Platform tanmay C++ Forum 2 24-Sep-2005 10:49
Unix! Zorachus Computer Software Forum - Linux 21 07-Aug-2005 10:33
Unix Flavours JdS Computer Software Forum - Linux 3 14-Jun-2005 10:36
equivalent expressions 81k5blzr C Programming Language 2 14-Feb-2005 13:52

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 09:37.


vBulletin, Copyright © 2000 - 2010, Jelsoft Enterprises Ltd.