Help needed with line-feed

Discussion in 'C Programming' started by Jrferguson, Feb 8, 2005.

  1. Jrferguson

    Jrferguson Guest

    I am 'dabling' with a piece of code:

    int k;
    for(k = 1; k < 6; k++)
    {
    printf("%3d\f", k)
    }
    with the expectation that the output would be something like:
    1
    2
    3 etc
    instead I get:
    1
    2
    3
    etc
    ie the \f is being treated as \n
    Any ideas please?
    John Ferguson
    Jrferguson, Feb 8, 2005
    #1
    1. Advertising

  2. In article <>,
    Jrferguson <> wrote:
    : printf("%3d\f", k)

    :with the expectation that the output would be something like:
    : 1
    : 2

    :ie the \f is being treated as \n

    The C89 standard says

    \f (form feed) Moves the active position to the start of the
    next logical page


    However, the meaning of "logical page" is implimentation dependant
    and possibly hardware dependant (terminal emulation software at least),
    so the behaviour you see is not inconsistant with the C standards.

    if you need the behaviour you were expecting, you should probably use
    a package such as curses.
    --
    Scintillate, scintillate, globule vivific
    Fain would I fathom thy nature specific.
    Loftily poised on ether capacious
    Strongly resembling a gem carbonaceous. -- Anon
    Walter Roberson, Feb 8, 2005
    #2
    1. Advertising

  3. Jrferguson

    Lew Pitcher Guest

    -----BEGIN PGP SIGNED MESSAGE-----
    Hash: SHA1

    Jrferguson wrote:
    > I am 'dabling' with a piece of code:
    >
    > int k;
    > for(k = 1; k < 6; k++)
    > {
    > printf("%3d\f", k)
    > }
    > with the expectation that the output would be something like:
    > 1
    > 2
    > 3 etc
    > instead I get:
    > 1
    > 2
    > 3
    > etc
    > ie the \f is being treated as \n


    According to my sources, "\f" "moves the active position to the initial
    position at the start of the next logical page."

    Apparently, your logical page is one line long.

    As for the left alignment, "initial position" usually means the leftmost
    position (in a left-to-right presentation media).

    > Any ideas please?
    > John Ferguson
    >



    - --

    Lew Pitcher, IT Specialist, Enterprise Data Systems
    Enterprise Technology Solutions, TD Bank Financial Group

    (Opinions expressed here are my own, not my employer's)
    -----BEGIN PGP SIGNATURE-----
    Version: GnuPG v1.2.4 (MingW32)

    iD8DBQFCCSgeagVFX4UWr64RArUJAJ9P1qeJC3wi07LZX+Fmh2fem2D4iACcDrgQ
    gbQJ426p4dfwsmgF/frZBqg=
    =ZHhA
    -----END PGP SIGNATURE-----
    Lew Pitcher, Feb 8, 2005
    #3
  4. Jrferguson

    Michael Mair Guest

    Jrferguson wrote:
    > I am 'dabling' with a piece of code:
    >
    > int k;
    > for(k = 1; k < 6; k++)
    > {
    > printf("%3d\f", k)
    > }
    > with the expectation that the output would be something like:
    > 1
    > 2
    > 3 etc
    > instead I get:
    > 1
    > 2
    > 3
    > etc
    > ie the \f is being treated as \n
    > Any ideas please?


    '\f' -- form feed.
    If you want to position the numbers abusing the field width of
    the printf() format, then consider
    int k;
    for(k = 1; k < 6; k++)
    {
    printf("%*d\n", 3*k, k)
    }
    I do not recommend this, though.
    If you want more console magic or free "positioning", then you
    are leaving the scope of standard C.


    Cheers
    Michael
    --
    E-Mail: Mine is an /at/ gmx /dot/ de address.
    Michael Mair, Feb 8, 2005
    #4
  5. Jrferguson wrote:

    > I am 'dabling' with a piece of code:
    >
    > for(int k = 1; k < 6; ++k) {
    > printf("%3d\f", k)
    > }
    >
    > with the expectation that the output would be something like:
    > 1
    > 2
    > 3 etc
    > instead I get:
    > 1
    > 2
    > 3
    > etc
    > i.e. the \f is being treated as \n


    No. '\f' is formfeed not linefeed.
    If you redirect output to a printer,
    you will get 6 pages of output
    with a single digit in the upper left hand corner of each page.

    > Any ideas please?


    UNIX operating systems interpret linefeed '\n'
    as the carriage return '\r' line feed '\n' sequence on Windows
    so you can't get just a linefeed.
    E. Robert Tisdale, Feb 8, 2005
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Mr. x
    Replies:
    0
    Views:
    1,476
    Mr. x
    Aug 28, 2003
  2. Chris R. Timmons
    Replies:
    0
    Views:
    656
    Chris R. Timmons
    Aug 29, 2003
  3. Dave Tichenor
    Replies:
    3
    Views:
    32,104
    Steven Cheng[MSFT]
    Feb 17, 2004
  4. =?Utf-8?B?UmFlZCBTYXdhbGhh?=

    Line Feed & Carriage Return with XML?

    =?Utf-8?B?UmFlZCBTYXdhbGhh?=, Oct 25, 2004, in forum: ASP .Net
    Replies:
    2
    Views:
    12,072
    Kevin Spencer
    Oct 25, 2004
  5. Domestos

    CSS and line feed help....

    Domestos, Jun 9, 2005, in forum: HTML
    Replies:
    4
    Views:
    2,666
    Mitja
    Jun 9, 2005
Loading...

Share This Page