Thread: What code will I used?

  1. #1
    Registered User
    Join Date
    Nov 2005
    Posts
    2

    What code will I used?

    What sourcecode will I used to accept the two strings inputs and will perform two running strings? The first string start from the left side of the screen, and the other one is from the right side that will meet at the center of the screen.

  2. #2
    ^ Read Backwards^
    Join Date
    Sep 2005
    Location
    Earth
    Posts
    282
    huh?

  3. #3
    Hardware Engineer
    Join Date
    Sep 2001
    Posts
    1,398
    ANSI/ISO Standard C++ only allows you to "print" characters to the screen like a typewriter... left to right, top to bottom.

    So, you'll have to look into your particular compiler's special display functions to see what's available. Perhaps this GotoXY FAQ will get you started.

    If you want to make the text "move", you'll most-likely have to write-over the existing text to create the illusion of movement, as you generally can't really move text around on the screen. (Although, I assume there are graphics libraries that can do it.)

  4. #4
    Registered User major_small's Avatar
    Join Date
    May 2003
    Posts
    2,787
    if you wanna do it in a standard way, you could create a string, output it, change it, clear it with with backspaces and spaces ('\b' and ' '), and then re-write it.

    it's VERY processor intensive though.

    edit: I got bored:
    Code:
    #include <iostream>	//for console I/O
    #include <string>	//for the stl string class
    #include <ctime>	//for a timer
    
    void wait(const int clocks);	//a timer to slow things down
    
    int main()
    {
    	std::string line1;	//the first word
    	std::string line2;	//the second word
    	std::string show;	//what gets shown on the screen
    
    	int l;			//the amount of spaces on the left
    	int r;			//the amount of spaces on the right
    	int m;			//the amount of spaces in the middle
    	
    	std::cout<<"Enter the first word: ";	//ask for the first word
    	getline(std::cin,line1,'\n');		//get the first word
    	std::cout<<"Enter the second word: ";	//ask for the second word
    	getline(std::cin,line2,'\n');		//get the second word
    
    	for(m=50,l=0,r=0; m>0; m-=2,l++,r++)	//loop, decreasing space between
    	{					//and increasing egde space
    		show.assign(l,' ');		//put the left spaces in
    		show.append(line1);		//put the first word in
    		show.append(m,' ');		//put the middle spaces in
    		show.append(line2);		//put the second word in
    		show.append(r,' ');		//put the right spaces in
    		
    		for(register int i=show.length();i>0;i--)
    		{
    			std::cout<<"\b \b";	//delete the previous line
    		}
    		
    		std::cout<<show<<std::flush;	//write this line
    		wait(100000);			//wait 100000 clock cycles
    	}
    	std::cout<<std::endl;			//you may need std::cin.get()
    	return 0;				//return 0
    }
    
    void wait(const int clocks)			//a timer to slow things down
    {
    	time_t start=clock();			//get the current clock time
    	while(clock()-start<clocks) {};		//loop until time has elapsed
    }
    it doesn't have them cross paths, because that's not really something you'll be able to do unless you get creative (maybe putting spaces in between each letter of both words and adding a new method to handle the crossover), but that's alot more work than I'm willing to do now
    Last edited by major_small; 11-29-2005 at 03:57 PM.
    Join is in our Unofficial Cprog IRC channel
    Server: irc.phoenixradio.org
    Channel: #Tech


    Team Cprog Folding@Home: Team #43476
    Download it Here
    Detailed Stats Here
    More Detailed Stats
    52 Members so far, are YOU a member?
    Current team score: 1223226 (ranked 374 of 45152)

    The CBoard team is doing better than 99.16% of the other teams
    Top 5 Members: Xterria(518175), pianorain(118517), Bennet(64957), JaWiB(55610), alphaoide(44374)

    Last Updated on: Wed, 30 Aug, 2006 @ 2:30 PM EDT

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Extended ASCII Characters in an RTF Control
    By JustMax in forum C Programming
    Replies: 18
    Last Post: 04-03-2009, 08:20 PM
  2. Enforcing Machine Code Restrictions?
    By SMurf in forum Tech Board
    Replies: 21
    Last Post: 03-30-2009, 07:34 AM
  3. Obfuscated Code Contest
    By Stack Overflow in forum Contests Board
    Replies: 51
    Last Post: 01-21-2005, 04:17 PM
  4. Interface Question
    By smog890 in forum C Programming
    Replies: 11
    Last Post: 06-03-2002, 05:06 PM
  5. Replies: 0
    Last Post: 02-21-2002, 06:05 PM