Go Back   PCMech Forums > Help & Discussion > Web Design / Development

Need Some Help? Type Your Keywords Here:

Reply
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
Old 12-17-2004, 03:21 AM   #1
Resident AMD enthusiast
 
Colonel Sanders's Avatar
 
Join Date: Jul 2001
Location: Kansas
Posts: 1,445
progress bars and such...

I was wondering if someone could help me figure out how to write a program which would simply display a "spinning line". By a spinning line I simply mean a character that would change, cycling through |, /, -, \, and back to | to give the illusion that the line is spinning. I know I've seen this on some flavors of Linux.

I only want this to show that the program is still running and not locked up, plus I think it looks cool. =)

Any suggestions?

TIA, L J
__________________
Main: Gigabyte GA-770T USB3 - Phenom II 840 - 4GB DDR3 - Radeon 5750 1GB
HTPC: MSI K9N6PGM2-V2 - Athlon II 250 - 4GB DDR2 - Radeon 5670 512MB
HTPC: Zotac GeForce 6100E-E - Athlon X2 5800+ - 4GB DDR2

"Play a Windows CD backwards and you'll hear satanic voices, thats nothing, play it forwards and it installs Windows."
Colonel Sanders is offline   Reply With Quote
Old 12-17-2004, 05:09 AM   #2
aym
Registered User
 
aym's Avatar
 
Join Date: Nov 2001
Posts: 1,965
Here you go:
Code:
#include <unistd.h>
#include <stdio.h>
                                                                                
int main(void) {
        char c[4] = "|/-\\";
        int i = 0;
        while (1) {
                printf("\r%c", c[i]);
                fflush(stdout);
                i = (i + 1) % 4;
                sleep(1);
        }
        return 0;
}
Ctrl+C to break out.

Last edited by aym; 12-17-2004 at 05:12 AM.
aym is offline   Reply With Quote
Old 12-17-2004, 09:50 AM   #3
Resident AMD enthusiast
 
Colonel Sanders's Avatar
 
Join Date: Jul 2001
Location: Kansas
Posts: 1,445
Is the second "\" in a row a typo or necessary, will fflush (stdout) clear the whole screen or just where the character, and how do I position this character at say, the upper right corner of the screen?

Also you say Ctrl + C to break out, what part of the code causes this? I was thinking of doing something like a while loop ( while x==0 ), then pushing a key would change the value of x to exit the program.

L J
Colonel Sanders is offline   Reply With Quote
Old 12-17-2004, 12:26 PM   #4
aym
Registered User
 
aym's Avatar
 
Join Date: Nov 2001
Posts: 1,965
No, the second \ is not a typo, \ is the escape character, \n means a new line for example, so you need two \s to actually get one \ .

fflush (stdout) sends the output from the buffer to the screen, it doesn't clear the screen, \r is the one that clears the previous character.

Ctrl+C sends a signal to the program, and the program exits because it doesn't handle the signal, your way to exit can be used too.
aym is offline   Reply With Quote
Old 12-18-2004, 02:00 PM   #5
Resident AMD enthusiast
 
Colonel Sanders's Avatar
 
Join Date: Jul 2001
Location: Kansas
Posts: 1,445
I'm pretty sure I have DJGPP configured wrong or something, I have compiled your code and another far less complex (just a little more advanced than a "hello world" app though) and the cursor randomly moves around the screen.

CMD proceeds to crash, than eventually I get an error something about "the file sent to LPT1 cant be printed, no printer attached"...

Any suggestions on how to configure DJGPP for Windows 2000? I am running version 2.03, which the DJGPP website claimed would work with Win2K...

TIA, L J

*any recomendations for a free compiler that will work with Windows 2000?

Last edited by Colonel Sanders; 12-18-2004 at 02:11 PM.
Colonel Sanders is offline   Reply With Quote
Old 12-21-2004, 04:49 AM   #6
aym
Registered User
 
aym's Avatar
 
Join Date: Nov 2001
Posts: 1,965
Hmm, I didn't test that under Windows, I thought you were looking for a Linux program.

For Windows, I suggest you try DevC++: (free)
http://www.bloodshed.net/dev/devcpp.html

Replace unistd.h with windows.h, and sleep(1) with Sleep(100).

Let me know if it works, I'll try to test it to under Windows too.
aym is offline   Reply With Quote
Reply

Bookmarks

Still Need Help? Type Your Keywords Here:


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes 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

BB code is On
Smilies are On
[IMG] code is On
HTML code is On
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -5. The time now is 07:14 AM.
Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2012, vBulletin Solutions, Inc.
SEO by vBSEO 3.6.0 PL2