CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Feb 2011
    Posts
    32

    Backspaces in printf - formatting question

    Hello.
    I have one question.
    For example, if we have this.
    Code:
    char *tmpString = "gorilla";
    printf("%10s", tmpString) -> this will output 3 backspaces in front of gorrila.
    However, what if I would want to declare an integer which will specifiy how many backspaces should be in front of string gorrila.
    For example:
    Code:
    char *tmpString = "gorilla";
    int countBackspaces = 10;
    printf("%countBackspaces%s", tmpString) -> something like this, but i dont know how...
    Is something like that even possible, i checked all manual on printf and backspaces and couldnt find the answers.
    Thank you.

  2. #2
    Join Date
    May 2001
    Location
    Germany
    Posts
    1,158

    Re: Backspaces in printf - formatting question

    IIRC, something like
    Code:
    printf("%*s", countBackspaces, tmpString );
    but shouldn't this be "spaces" or "blanks" instead of backspaces?

  3. #3
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    7,825

    Re: Backspaces in printf - formatting question

    All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!

    C++23 Compiler: Microsoft VS2022 (17.6.5)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured