|
|||||||
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
#1 |
|
Resident AMD enthusiast
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." |
|
|
|
|
|
#2 |
|
Registered User
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;
}
Last edited by aym; 12-17-2004 at 05:12 AM. |
|
|
|
|
|
#3 |
|
Resident AMD enthusiast
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 |
|
|
|
|
|
#4 |
|
Registered User
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. |
|
|
|
|
|
#5 |
|
Resident AMD enthusiast
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. |
|
|
|
|
|
#6 |
|
Registered User
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. |
|
|
|
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|