Thread: is there another way to PAUSE the command prompt ?!

  1. #1
    C 1337 Meshal's Avatar
    Join Date
    Nov 2006
    Posts
    70

    is there another way to PAUSE the command prompt ?!

    is there another way to PAUSE the command prompt without using

    Code:
    system(PAUSE);
    ??!!

  2. #2
    erstwhile
    Join Date
    Jan 2002
    Posts
    2,227
    faq.
    CProgramming FAQ
    Caution: this person may be a carrier of the misinformation virus.

  3. #3
    C 1337 Meshal's Avatar
    Join Date
    Nov 2006
    Posts
    70
    thnks

  4. #4
    C 1337 Meshal's Avatar
    Join Date
    Nov 2006
    Posts
    70
    but there is a simple questions --->

    what fflush() really do ??

    i read that it :
    fflush() causes any unwritten data for that stream to be written to the file
    fflush() function causes any buffered output data for stream to be written to file

    but i don`t understand what buffered mean here !!

    what`s the buffered output data

    ex:

    FILE *fp = fopen("file.txt","rw");
    fflush(fp);
    is this meaningfull ??

    and there is something called flush()
    is it the same with fflush()

    i know i ask many question but i want to learn that`s all ..

  5. #5
    Registered User
    Join Date
    Apr 2006
    Posts
    2,149
    Quote Originally Posted by Meshal
    but there is a simple questions --->

    what fflush() really do ??

    i read that it :
    fflush() causes any unwritten data for that stream to be written to the file
    fflush() function causes any buffered output data for stream to be written to file
    When you work with a file, the data that you write to the file is first stored in a memmory 'buffer'. When this buffer gets full, or when you tell the program to flush the buffer, then any data in the buffer gets writen to the harddisk or wherever the file is actually located.
    It is too clear and so it is hard to see.
    A dunce once searched for fire with a lighted lantern.
    Had he known what fire was,
    He could have cooked his rice much sooner.

  6. #6
    C 1337 Meshal's Avatar
    Join Date
    Nov 2006
    Posts
    70
    Quote Originally Posted by King Mir
    When you work with a file, the data that you write to the file is first stored in a memmory 'buffer'. When this buffer gets full, or when you tell the program to flush the buffer, then any data in the buffer gets writen to the harddisk or wherever the file is actually located.
    ammm , so why this program doesn`t do as you say ?

    Code:
    main()
    {
    
    FILE *fp = fopen("file.txt","r+w"); //file.txt empty file!
    
    printf("this will be printed to the file");
    
    fflush(fp);
    }
    after opening the file file.txt i see nothing ?! why

  7. #7
    Registered User OnionKnight's Avatar
    Join Date
    Jan 2005
    Posts
    555
    Quote Originally Posted by Meshal
    ammm , so why this program doesn`t do as you say ?

    Code:
    main()
    {
    
    FILE *fp = fopen("file.txt","r+w"); //file.txt empty file!
    
    printf("this will be printed to the file");
    
    fflush(fp);
    }
    after opening the file file.txt i see nothing ?! why
    No, it will be printed to stdout. Use
    Code:
    fprintf(fp, "this will be printed to the file");
    instead.

  8. #8
    Registered User ssharish2005's Avatar
    Join Date
    Sep 2005
    Location
    Cambridge, UK
    Posts
    1,732
    Quote Originally Posted by Meshal
    is there another way to PAUSE the command prompt without using

    Code:
    system(PAUSE);
    ??!!
    can use getchar() as well

    ssharish2005

  9. #9
    C 1337 Meshal's Avatar
    Join Date
    Nov 2006
    Posts
    70
    till now i don`t know why we need fflush() and how we use it in the program

  10. #10
    Lurking whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    9,612
    There is at least one level of indirection from raw input from hardware to your output device (perhaps a screen). The memory where this input is stored needs to be flushed as it fills up with data, so that you don't run into a situation where the memory is full and you miss something, or worse, can't accept new input. Now, in C's standard implementation, the OS will typically make an educated guess, flushing this memory if it recieves a newline and whatever data it contained is written to the output device.

    Now if you neglect to include a newline with your output or the system doesn't flush when you expect it to, you need to do it yourself, hence, fflush(FILE*).

    fflush only works with output streams (like files opened with "w" and stdout) and not input streams (like stdin). This is chiefly because writing to an input stream does not make any sense. Can you write to a keyboard? How about a mouse? Input devices "read things" or report events only, and have no business doing any "writing," as far as I know.

  11. #11
    C 1337 Meshal's Avatar
    Join Date
    Nov 2006
    Posts
    70
    understood , and i need to know about system more
    i`ll buy then (Advanced Unix Programming) to learn more about this stuff !

    thanks for your help and explain to fflush ,

    but there is still a question hasn`t been answered !!!!!!!!!!

    =========================
    and there is something called flush()
    is it the same with fflush()
    =========================

  12. #12
    Lurking whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    9,612
    > and there is something called flush()
    Not in standard C.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Fork(), pause(), and storing PID's in a linked list
    By vital101 in forum C Programming
    Replies: 10
    Last Post: 09-28-2007, 02:16 AM
  2. Why doesn't this cin.get() pause the program?
    By Loctan in forum C++ Programming
    Replies: 5
    Last Post: 06-24-2006, 04:06 PM
  3. pause
    By Moffesto in forum C++ Programming
    Replies: 4
    Last Post: 06-21-2002, 10:15 AM
  4. Problem with the pause function
    By indigo0086 in forum C++ Programming
    Replies: 1
    Last Post: 11-03-2001, 12:38 PM
  5. Pause function ???
    By Unregistered in forum C++ Programming
    Replies: 8
    Last Post: 09-02-2001, 08:22 PM