problem with printf

This is a discussion on problem with printf within the C Programming forums, part of the General Programming Boards category; I am trying to use printf in a way so it will start printing 20 spaces into the page. I ...

  1. #1
    Registered User
    Join Date
    Sep 2001
    Posts
    2

    Talking problem with printf

    I am trying to use printf in a way so it will start printing 20 spaces into the page. I know how to do this when a variable is involved but I am just trying to print a string of characters (ie printf "this is a test"If anyone can show me how to format this properly so I can compile the program it would help a lot.

  2. #2
    Mayor of Awesometown Govtcheez's Avatar
    Join Date
    Aug 2001
    Location
    MI
    Posts
    8,825
    Why wouldn't
    Code:
    printf("                                                        This is a test");
    work?


    (author of post collapses as blinking winner banner causes seizure)

  3. #3
    Registered User
    Join Date
    Sep 2001
    Posts
    2
    thats not the answer I was looking for....any smart solutions.

  4. #4
    Mayor of Awesometown Govtcheez's Avatar
    Join Date
    Aug 2001
    Location
    MI
    Posts
    8,825
    Not smart enough? Um... why not?

    Use a loop, then.

  5. #5
    Skunkmeister Stoned_Coder's Avatar
    Join Date
    Aug 2001
    Posts
    2,572
    you could look for gotoxy(int,int) in conio.h

    If you are using MSVC you will have to write it yourself....
    Code:
    void gotoxy(int x, int y) 
    { 
    COORD point; 
    point.X = x; point.Y = y; 
    SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE),point); 
    }
    Free the weed!! Class B to class C is not good enough!!
    And the FAQ is here :- http://faq.cprogramming.com/cgi-bin/smartfaq.cgi

  6. #6
    Has a Masters in B.S.
    Join Date
    Aug 2001
    Posts
    2,267
    heres the SMARTEST and EASIEST

    char test[] = " this is a test";
    printf("%*s",20 + strlen(test),test);

  7. #7
    Mayor of Awesometown Govtcheez's Avatar
    Join Date
    Aug 2001
    Location
    MI
    Posts
    8,825
    I still don't get why my first response, or this:
    Code:
    for(i=0;i<20;i++)
        printf(" ");
    printf("This is a test");
    isn't good enough...

  8. #8
    Has a Masters in B.S.
    Join Date
    Aug 2001
    Posts
    2,267
    come now govt you must see which is easiest.

    Stoned's is perfectly fine yet it requires to much work and careful and thoughtful manipulation of the screen.

    your's way is just plain uneccessary.

    and mine is just simplest.
    Last edited by no-one; 09-17-2001 at 10:40 AM.
    ADVISORY: This users posts are rated CP-MA, for Mature Audiences only.

  9. #9
    Registered User
    Join Date
    Aug 2001
    Posts
    72
    another one without invoking the strlen()

    printf ("%20c%s", ' ', pszTest);

  10. #10
    Mayor of Awesometown Govtcheez's Avatar
    Join Date
    Aug 2001
    Location
    MI
    Posts
    8,825
    Eh, I just though my way would look simpler to noobs out there...

    Whatever, doesn't matter...

  11. #11
    Registered User Natase's Avatar
    Join Date
    Aug 2001
    Posts
    123
    made4 drivers:

    Why don't you just adapt the "smart solution" you already have for printing 20 spaces before a variable.

    All you would need to do is replace the '%s' in your printf with the actual string of characters.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Problems reading entered race times C
    By loopymoo26 in forum C Programming
    Replies: 12
    Last Post: 05-23-2009, 07:38 AM
  2. Help with a C Programing Quiz project
    By dilemma in forum C Programming
    Replies: 12
    Last Post: 05-15-2009, 03:35 PM
  3. A question related to strcmp
    By meili100 in forum C++ Programming
    Replies: 6
    Last Post: 07-07-2007, 02:51 PM
  4. error in program????
    By SpEkTrE in forum C Programming
    Replies: 5
    Last Post: 11-24-2003, 05:16 PM
  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