a printf thing

This is a discussion on a printf thing within the C Programming forums, part of the General Programming Boards category; its a console app compiled in BC 4.5 is there an easy way to printf a status to the screen ...

  1. #1
    and the Hat of Clumsiness GanglyLamb's Avatar
    Join Date
    Oct 2002
    Location
    between photons and phonons
    Posts
    1,109

    a printf thing

    its a console app compiled in BC 4.5
    is there an easy way to printf a status to the screen
    for example
    Code:
    printf("Status:%d%%",status);
    now status the variable goes from 0 till 100 but is there anyway that i can make only the percentage change because else u get something like
    /*outprint*/
    Status:1%
    Status:2%
    Status:3%

    and so on and what i want is something like
    Status:and here a number that changes%

    i tried to printf then formfeed or clrscr and then printf again but if
    %d,status goes at 1%/sec then you see it clears the screen
    anyway mayb somebody knows this ....if its possible in a console app

  2. #2
    Registered User Pioneer's Avatar
    Join Date
    Dec 2002
    Posts
    59
    Code:
    #include <stdio.h>
    #include <time.h>
    
    waitie(double seconds){
        clock_t end = clock() + (seconds * CLOCKS_PER_SEC);
    
        while (clock() < end)
            ;
    }
    
    main(){
        int stat = 0;
    
        while (stat < 100){
            printf("Status:%d%%\r", stat++);
            waitie(.2);
        }
    
        printf("Complete...\n");
    }

  3. #3
    Registered User Pioneer's Avatar
    Join Date
    Dec 2002
    Posts
    59
    Can you explain why it's trash, please?

  4. #4
    and the Hat of Clumsiness GanglyLamb's Avatar
    Join Date
    Oct 2002
    Location
    between photons and phonons
    Posts
    1,109
    Sorry, but this code is trash and you do yourself and everbody who uses your programs a favour if you don't put that into your source. Use Sleep( ) from windows.h or sleep( ) from unistd.h.
    =>
    thx VvV it works just fine.
    im stupified tosay this but i didnt even know there was an escape sequence \r :$ =>i think thist is what u get if u start learning c without any book except for the library reference in the compiler..;;

  5. #5
    moi
    moi is offline
    Registered User moi's Avatar
    Join Date
    Jul 2002
    Posts
    946
    i don't think \r is standard, but it works it's carridge return w/o linefeed, moves the cursor back to beginning of line.
    hello, internet!

  6. #6
    Registered User Pioneer's Avatar
    Join Date
    Dec 2002
    Posts
    59
    That's a good reason, thanks. But seeing as how I'm the only user I'll do what I want. If I write a program for something multi-user then I'll use a better waiting function. Also, windows.h and unistd.h can't be used everywhere, my function can, anti-social or not. One last thing, you could be a little nicer when you bash someone else's programs, imagine how I felt when you said it was trash with no apparent reason.

  7. #7
    Registered User Pioneer's Avatar
    Join Date
    Dec 2002
    Posts
    59
    I'll survive if my music hangs for a little bit. About the conditional compilation, I've seen a lot of different ways to do it, would this work?
    Code:
    #include <stdio.h>
    
    #if !defined(_WIN32)
        #include <unistd.h>
    #else
        #include <windows.h>
        #define sleep Sleep
    #endif
    
    main(){
        int stat = 0;
    
        while (stat < 100){
            printf("Status:%d%%\r", stat++);
            sleep(100);
        }
    
        printf("Complete...\n");
    }
    Or should I test for unistd.h?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Help with a C Programing Quiz project
    By dilemma in forum C Programming
    Replies: 12
    Last Post: 05-15-2009, 03:35 PM
  2. menu problem!!! need U R G E N T help!!!
    By catcat28 in forum C Programming
    Replies: 16
    Last Post: 11-19-2007, 12:32 PM
  3. Contest Results - May 27, 2002
    By ygfperson in forum A Brief History of Cprogramming.com
    Replies: 18
    Last Post: 06-18-2002, 01:27 PM
  4. Azbia - a simple RPG game code
    By Unregistered in forum Game Programming
    Replies: 11
    Last Post: 05-03-2002, 06:59 PM
  5. Replies: 22
    Last Post: 11-08-2001, 10:01 PM

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