Turn on thread page Beta

c programming watch

Announcements

    I've downloaded a C compiler and compiled some programs without any errors. when i run them they just appear on the screen for a split second and go away. How can i keep them on there?

    cheers
    Offline

    0
    ReputationRep:
    (Original post by mhg)
    I've downloaded a C compiler and compiled some programs without any errors. when i run them they just appear on the screen for a split second and go away. How can i keep them on there?

    cheers
    i assume you are running the programs in Windows?
    Offline

    15
    ReputationRep:
    (Original post by mhg)
    I've downloaded a C compiler and compiled some programs without any errors. when i run them they just appear on the screen for a split second and go away. How can i keep them on there?

    cheers
    some compilers have a special function which prints "pless any key to continue" and waits before exitiong; for example, in Dev C++ just put :
    Code:
    system("PAUSE");
    before your return.

    alternatively if the compiler doesn't support this, you could do it yourself:

    Code:
    printf("Press return to continue...\n");
    scanf("%c");
    or you could use the dos prompt (if you're using windows) to run your programs, as it won't close after execution
    Offline

    0
    ReputationRep:
    (Original post by elpaw)
    some compilers have a special function which prints "pless any key to continue" and waits before exitiong; for example, in Dev C++ just put :
    Code:
    system("PAUSE");
    before your return.

    alternatively if the compiler doesn't support this, you could do it yourself:

    Code:
    printf("Press return to continue...\n");
    scanf("%c");
    or you could use the dos prompt (if you're using windows) to run your programs, as it won't close after execution
    or just run the program in dos?
    Offline

    15
    ReputationRep:
    (Original post by vienna95)
    or just run the program in dos?
    or just go straight to the source and run it in UNIX
    Offline

    0
    ReputationRep:
    Header File

    conio.h

    Category

    Console I/O Routines

    Prototype

    int getch(void);

    Description

    Gets character from keyboard, does not echo to screen.

    getch reads a single character directly from the keyboard, without echoing to the screen.

    Note: Do not use this function in Win32 GUI applications.

    Return Value

    getch returns the character read from the keyboard.

    From the Borland help.

    I emulated this function in masm32, this is a little gift hehe:

    getch PROC uses ecx edx
    .if stdin_started == 0
    invoke start_stdin
    .if stdin_started == 0
    ret
    .endif
    .endif
    mov ird.EventType,KEY_EVENT
    repeat_loop:
    invoke ReadConsoleInput,stdin,offset ird,1,offset Num
    .if ird.Event.bKeyDown == TRUE
    jmp repeat_loop
    .endif
    xor eax,eax
    mov ax,ird.Event.wVirtualScanCode
    ret
    getch ENDP

    start_stdin PROC
    LOCAL STATE: DWORD
    .if stdin_started == 0
    invoke GetStdHandle,STD_INPUT_HANDLE
    .if eax != 0
    mov stdin,eax
    mov stdin_started,1
    invoke FlushConsoleInputBuffer,stdin
    .endif
    .endif
    ret
    start_stdin ENDP

 
 
 
Poll
Cats or dogs?
Useful resources

The Student Room, Get Revising and Marked by Teachers are trading names of The Student Room Group Ltd.

Register Number: 04666380 (England and Wales), VAT No. 806 8067 22 Registered Office: International House, Queens Road, Brighton, BN1 3XE

Write a reply...
Reply
Hide
Reputation gems: You get these gems as you gain rep from other members for making good contributions and giving helpful advice.