Thread: Making a text based progress bar

  1. #1
    Registered User TmX's Avatar
    Join Date
    Sep 2006
    Posts
    14

    Making a text based progress bar

    I found a BCX code about making a text based progress bar:
    http://d-apps.com/files/coding/bcx/cprog.zip

    I tried to rewrite the code in C, and this is the result:
    Code:
    #include <windows.h>
    #include <stdio.h>
    
    void gotoxy(int,int);
    
    int main(){
    	int iPercent = 10000000;
    	int rCounter;
    	int iTmpMth1 = 0;
    	int iPrevCnt = 0;
    	CONSOLE_SCREEN_BUFFER_INFO sbi;
    	HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
    	GetConsoleScreenBufferInfo(hConsole, &sbi);
    	
    	for (rCounter = 0; rCounter < iPercent; rCounter++){
    		iTmpMth1 = 8 + (rCounter / iPercent) * 54;
    		if (iPrevCnt != iTmpMth1) {
    			gotoxy(sbi.dwCursorPosition.Y + 3, iTmpMth1);
    			printf("#");
    			iPrevCnt = iTmpMth1;
    		}
    	}
    	return 0;
    }
    
    void gotoxy(int x, int y){
    	COORD point;
    	point.X = x;
    	point.Y = y;
    	SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), point);
    }
    Well, no animation there. I can't figure out what's wrong...

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    So rCounter / iPercent will always and forever equal 0; consequently iTmpMth1 will always be 8. Maybe you should make iPercent a floating-point variable.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 6
    Last Post: 01-29-2008, 04:40 AM
  2. Progress Bar
    By Stabbsy in forum Windows Programming
    Replies: 4
    Last Post: 11-04-2007, 10:30 PM
  3. A bunch of Linker Errors...
    By Junior89 in forum Windows Programming
    Replies: 4
    Last Post: 01-06-2006, 02:59 PM
  4. File Through Winsock & Progress on bar
    By (TNT) in forum Windows Programming
    Replies: 4
    Last Post: 12-05-2001, 10:50 PM
  5. Outputting String arrays in windows
    By Xterria in forum Game Programming
    Replies: 11
    Last Post: 11-13-2001, 07:35 PM