Thread: linux bash command prompt access with c++

  1. #1
    Registered User
    Join Date
    Jun 2008
    Posts
    106

    linux bash command prompt access with c++

    How can I control the command prompt with c++ in linux? I am using bash.

    For learning, I am trying to make a rotating bar using | \ - / characters

    print |
    erase
    print \
    erase
    print -
    erase
    print /

    ...and this would be looped

    I just need to know how to stream to the command prompt and how to erase characters

  2. #2
    Registered User
    Join Date
    Dec 2005
    Location
    Canada
    Posts
    267

    OS: Windows 7, XUbuntu 11.10, Arch Linux
    IDE: CodeBlocks
    Compiler: GCC

  3. #3
    Deathray Engineer MacGyver's Avatar
    Join Date
    Mar 2007
    Posts
    3,210
    One possible way to erase, would be to type a '\b' char and then overwrite. It's not the best necessarily, but it's the most portable to try (although it may or may not work). Something like this:

    Code:
    #include <iostream>
    
    void doIter();
    
    void doIter()
    {
    	char szIter[] = {'|', '/', '\\', '-'};
    	
    	for(size_t i=0;i<sizeof(szIter)/sizeof(*szIter);i++)
    	{
    		putchar(szIter[i]);
    		putchar('\b');
    	}
    }
    
    int main()
    {
    	for(size_t i=0;i<5000;i++)
    	{
    		doIter();
    	}
    	
    	return 0;
    }
    Last edited by MacGyver; 06-30-2008 at 09:35 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Some common Linux Questions???
    By code2d in forum Tech Board
    Replies: 4
    Last Post: 12-28-2006, 02:17 AM
  2. Linux: Use C to call a bash script
    By harada in forum Linux Programming
    Replies: 9
    Last Post: 10-27-2006, 01:59 PM
  3. Linux Version reccomendation
    By Pobega in forum A Brief History of Cprogramming.com
    Replies: 28
    Last Post: 10-05-2006, 06:48 PM
  4. linux wont boot
    By GanglyLamb in forum Tech Board
    Replies: 4
    Last Post: 02-13-2003, 04:04 PM
  5. Which distribution of Linux should I get?
    By joshdick in forum A Brief History of Cprogramming.com
    Replies: 50
    Last Post: 01-19-2003, 09:26 AM