about printf

This is a discussion on about printf within the C Programming forums, part of the General Programming Boards category; How do I print from right to left using printf? Do I need a specific escape sequence? For example I ...

  1. #1
    Registered User
    Join Date
    Mar 2005
    Posts
    3

    about printf

    How do I print from right to left using printf? Do I need a specific escape sequence? For example I need to print
    ************
    ***** *****
    **** ****
    *** ***
    ** **
    * *

    but when I run my program I get


    ************
    ***** *****
    **** ****
    *** ***
    ** **
    * *
    Any suggestions would be appreciated.

  2. #2
    Registered User
    Join Date
    Mar 2005
    Posts
    3
    Sorry, the picture didnt turn out like I expected.

  3. #3
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,006
    >Sorry, the picture didnt turn out like I expected.

    Edit it and use [code][/code] tags to preserve spacing. And post your code as well.
    Last edited by Dave_Sinkula; 03-24-2005 at 04:24 PM.
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

  4. #4
    former member Brain Cell's Avatar
    Join Date
    Feb 2004
    Posts
    472
    I saw what you ment by hovering the mouse on the topic in the forum.

    I don't think you can write from right to left. however , you could figure an algorithm that knows how many spaces there are between the two shapes.

    It simply goes like this :
    - output 6 and 6 asterisks on the first line.
    - output 5 asterisks , a space and another 5 asterisks.
    - output 4 asterisks , two spaces and another 4 asterisks

    and so on...


    hope this helps
    My Tutorials :
    - Bad programming practices in : C
    - C\C++ Tips
    (constrcutive criticism is very welcome)


    - Brain Cell

  5. #5
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,498
    > Any suggestions would be appreciated.
    Posting your code would help
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  6. #6
    Registered User
    Join Date
    Mar 2005
    Posts
    3
    ok my program is:

    Code:
    for (i=1; i>1; i--)
    { 
       for (j=1, J<=i, J++)
        printf("*");
      for(k=i; k<n; k++)
       printf(" ");
       for (j=1; j<=i; j++)
      printf("*");
    I just have a nested for loop, and it is the last for loop which needs to be changed. Im just stuck.

  7. #7
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,498
    And for those still not paying attention - an interlude

    <pointless music>
    << !! Posting Code? Read this First !! >>
    </pointless music>

    Your thread will resume once you've read that and edited your post accordingly.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  8. #8
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,006
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

  9. #9
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,498
    LOL!
    Now, if we can find a good "use code tags" theme music, we can add it to all the posts

    > for (i=1; i>1; i--)
    Well you could post the code which produced your results, because this code isn't it.
    This loop never runs, it immediately fails the first test ( 1 is not > 1 )
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  10. #10
    Work in Progress..... Jaken Veina's Avatar
    Join Date
    Mar 2005
    Location
    Missouri. Go Imos Pizza!
    Posts
    256
    Perhaps you could tell us what n is?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. making it portable.....?
    By ShadeS_07 in forum C Programming
    Replies: 11
    Last Post: 12-24-2008, 08:38 AM
  2. get keyboard and mouse events
    By ratte in forum Linux Programming
    Replies: 10
    Last Post: 11-17-2007, 04:42 PM
  3. segmentation fault upon reload
    By yabud in forum C Programming
    Replies: 8
    Last Post: 12-18-2006, 05:54 AM
  4. Simple C question: user input to repeat a loop
    By evernaut in forum C Programming
    Replies: 2
    Last Post: 11-18-2006, 08:23 AM
  5. Drawing tables in C
    By stanoman in forum C Programming
    Replies: 5
    Last Post: 10-09-2003, 10:14 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21