Thread: help with trying to move a block of output to the left

  1. #1
    Registered User
    Join Date
    Dec 2012
    Posts
    28

    help with trying to move a block of output to the left

    Hello everyone! I have a block of output that I want to be moved to the left on the console as much as possible.Here is the code I have:
    Code:
     do
     {
       printf("%*s" "%s", height, " ",  " "); 
    
          for (int i=0; newheight>=i;i++)
          {
           printf ( "#");
          }
     
       printf("\n");
       newheight=newheight+1;
       height=height-1;
     }while(newheight<=tempheight);
    the code works and prints the proper number of #.But I cant get it to print to the far left. Any suggestions would be greatly appreciated. thanks!

  2. #2
    Registered User
    Join Date
    Mar 2010
    Posts
    583
    The far left?

    Well, you do this at the beginning of every line
    Code:
      printf("%*s" "%s", height, " ",  " ");
    You're padding it out from the left hand side by "height" but also always by 2 characters.
    If you want it to keep the same shape but touch the left hand side of the window, then removing those extra spaces should do it.
    If you want it to be aligned to the left hand side, remove the printf of those spaces altogether.

    Or - if you're on a system where you can't normally get to the far left of the screen, there's usually a way to move the cursor, but it'll be OS specific. E.g. setCursorPos SetCursorPos function (Windows) on Windows.


    Or if I've completely missed your point, what are you actually trying to do? What's this code meant to achieve.... why are you using a "height" variable for horizontal spacing?

  3. #3
    Registered User
    Join Date
    Dec 2012
    Posts
    28
    Quote Originally Posted by smokeyangel View Post
    The far left?

    Well, you do this at the beginning of every line
    Code:
      printf("%*s" "%s", height, " ",  " ");
    You're padding it out from the left hand side by "height" but also always by 2 characters.
    If you want it to keep the same shape but touch the left hand side of the window, then removing those extra spaces should do it.
    If you want it to be aligned to the left hand side, remove the printf of those spaces altogether.

    Or - if you're on a system where you can't normally get to the far left of the screen, there's usually a way to move the cursor, but it'll be OS specific. E.g. setCursorPos SetCursorPos function (Windows) on Windows.


    Or if I've completely missed your point, what are you actually trying to do? What's this code meant to achieve.... why are you using a "height" variable for horizontal spacing?


    I want the highest blocks to be hitting the far left hand side..for example

    ##
    ###
    ####

  4. #4
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    What is the current output? You may want to post it within [code][/code] bbcode tags.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  5. #5
    Registered User
    Join Date
    Dec 2012
    Posts
    28
    This is the output I have:

    ###
    #####
    #######


    And this is the code:
    Code:
     do
     {
      printf("%*s" "%s", height, " ",  " "); 
    
          for (int i=0; newheight>=i;i++)
          {
           printf ( "#");
          }
    The output should be touching the bottom left hand corner of the screen, but it isnt. Any suggestions on how format it to do so? thanks

  6. #6
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Quote Originally Posted by saldar05
    The output should be touching the bottom left hand corner of the screen, but it isnt. Any suggestions on how format it to do so?
    Oh, now I understand. Unfortunately, there is no standard way of doing this. One way is to simply assume the number of rows, and then print blank lines such that the output appears to be "touching the bottom left hand corner of the screen".
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. C compiler reads from right to left or left to right?
    By ajishgopalr in forum C Programming
    Replies: 12
    Last Post: 07-16-2011, 08:12 PM
  2. Left()
    By cbrandy in forum C Programming
    Replies: 1
    Last Post: 02-20-2011, 05:28 AM
  3. how to * move????
    By shah18 in forum C Programming
    Replies: 5
    Last Post: 10-04-2010, 11:38 AM
  4. When to move on?
    By SushiFugu in forum C++ Programming
    Replies: 5
    Last Post: 01-03-2002, 09:05 PM
  5. want to move bmp
    By b_amit4u in forum C Programming
    Replies: 3
    Last Post: 12-09-2001, 03:40 AM