Lost Password?


Go Back   CodeCall Programming Forum > Software Development > C and C++

C and C++ C and C++ forum for discussing all forms of C except for C#. These languages are powerful low level languages used for creating Operating Systems, Device Drivers, compilers and much more.

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 04-01-2008, 04:26 PM
bladactania bladactania is offline
Newbie
 
Join Date: Apr 2008
Posts: 9
Rep Power: 0
bladactania is on a distinguished road
Default Moving the cursor

I'm using C in a terminal window. I am printing out the % completed. I want the program to print the percentage in the same place each time so I don't get

0%
1%
2%
3%
4%

and so on. I want to move the cursor to the beginning of the same line and overwrite. Is there a way to do this?

Thanks
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

Sponsored Links
  #2 (permalink)  
Old 04-01-2008, 04:35 PM
TkTech TkTech is offline
 
Join Date: Jun 2006
Posts: 1,034
Last Blog:
Having trouble with yo...
Rep Power: 20
TkTech is on a distinguished road
Send a message via MSN to TkTech
Default Re: Moving the cursor

Are you on windows?
__________________
CodeCall Blog | CodeCall Wiki | Shareware | Linux Forum
Chat with other CodeCall members on IRC; connect to irc.codecall.net and join #codecall
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 04-01-2008, 04:41 PM
bladactania bladactania is offline
Newbie
 
Join Date: Apr 2008
Posts: 9
Rep Power: 0
bladactania is on a distinguished road
Default Re: Moving the cursor

Linux at the moment. But I'd like to be able to do it for windows too.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 04-01-2008, 04:48 PM
TkTech TkTech is offline
 
Join Date: Jun 2006
Posts: 1,034
Last Blog:
Having trouble with yo...
Rep Power: 20
TkTech is on a distinguished road
Send a message via MSN to TkTech
Default Re: Moving the cursor

Just print a backspace.

Or, on windows, SetConsoleCursor in shell32.dll
__________________
CodeCall Blog | CodeCall Wiki | Shareware | Linux Forum
Chat with other CodeCall members on IRC; connect to irc.codecall.net and join #codecall
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 04-01-2008, 04:57 PM
bladactania bladactania is offline
Newbie
 
Join Date: Apr 2008
Posts: 9
Rep Power: 0
bladactania is on a distinguished road
Default Re: Moving the cursor

how do I print a backspace? I thought printf("\b"); but that didn't work.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

Sponsored Links
  #6 (permalink)  
Old 04-08-2008, 01:27 AM
Aereshaa's Avatar   
Aereshaa Aereshaa is offline
Guru
 
Join Date: Apr 2008
Posts: 539
Rep Power: 9
Aereshaa is a jewel in the roughAereshaa is a jewel in the roughAereshaa is a jewel in the roughAereshaa is a jewel in the rough
Default Re: Moving the cursor

Well, I'd use DEL characters, not backspaces::
Code:
printf("%d%%",percent);
printf("\x7f\x7f");
The ascii DEL character is hexadecimal 7F, and deletes the character before it. Hope that helps.

Last edited by Aereshaa; 04-08-2008 at 04:32 PM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #7 (permalink)  
Old 04-08-2008, 05:19 AM
Zed Zed is offline
Newbie
 
Join Date: Apr 2008
Posts: 4
Rep Power: 0
Zed is on a distinguished road
Default Re: Moving the cursor

Hi, can you please paste here the code which printing out this text.
0%
1%
2%
3%
4%


Thanks.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #8 (permalink)  
Old 04-08-2008, 08:23 AM
Xav's Avatar   
Xav Xav is offline
Code Warrior
 
Join Date: Mar 2008
Location: On God's Planet
Posts: 9,897
Last Blog:
Web slideshow in JavaS...
Rep Power: 78
Xav has much to be proud ofXav has much to be proud ofXav has much to be proud ofXav has much to be proud ofXav has much to be proud ofXav has much to be proud ofXav has much to be proud ofXav has much to be proud of
Send a message via MSN to Xav
Default Re: Moving the cursor

You could display it in a progress bar. I know that isn't really feasible in a Linux command line application, but you could try doing it like this:

|||||||||||||||||||||||||||

Just a challenge.
__________________


Mr. Xav | Website | Forums | Blog
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #9 (permalink)  
Old 04-15-2008, 04:10 PM
Aereshaa's Avatar   
Aereshaa Aereshaa is offline
Guru
 
Join Date: Apr 2008
Posts: 539
Rep Power: 9
Aereshaa is a jewel in the roughAereshaa is a jewel in the roughAereshaa is a jewel in the roughAereshaa is a jewel in the rough
Default Re: Moving the cursor

hmm.. I've done a bit of research, and you could do it with ansi escape sequences:
Code:
for(int prcnt = 0;prcnt != 100;prcnt++){
printf("%d%%",prcnt);?//prints 1% 2% etc 
fputs("\033[A");//this escape code moves the cursor up by one.
}
this will work on all operating systems, even windows.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #10 (permalink)  
Old 04-15-2008, 04:17 PM
Xav's Avatar   
Xav Xav is offline
Code Warrior
 
Join Date: Mar 2008
Location: On God's Planet
Posts: 9,897
Last Blog:
Web slideshow in JavaS...
Rep Power: 78
Xav has much to be proud ofXav has much to be proud ofXav has much to be proud ofXav has much to be proud ofXav has much to be proud ofXav has much to be proud ofXav has much to be proud ofXav has much to be proud of
Send a message via MSN to Xav
Default Re: Moving the cursor

Oh, OK. Glad you found the solution. For a challenge, though, try the progress bar. You could do it with continuous pipe symbols (|) to build up a visual representation of the percentage.
__________________


Mr. Xav | Website | Forums | Blog
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

Sponsored Links
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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 Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Creating a Custom Cursor ahsan16 Tutorials 2 01-13-2007 06:03 PM
Moving charts fom excel to word. priorityone Computer Software/OS 4 01-07-2007 06:19 AM
Moving elements in an array Fischerspooner General Programming 9 12-12-2006 09:24 PM
PR - Moving Sale Montecarlo Marketing 3 07-21-2006 11:47 AM


All times are GMT -5. The time now is 11:39 AM.

Contest Stats

WingedPanther ........ 2753.6
Xav ........ 2704
Brandon W ........ 1702.32
John ........ 1207.73
marwex89 ........ 1175.24
morefood2001 ........ 966.05
dcs ........ 655.75
Steve.L ........ 475.59
orjan ........ 418.58
Aereshaa ........ 383.54

Contest Rules

CodeCall Goal

Goal: 100,000 Posts
Complete: 101%


Complete - Celebrate!

Ads