Printf Format String - Risks of Using Field Width Versus Explicit Delimiters in Tabular Output

Risks of Using Field Width Versus Explicit Delimiters in Tabular Output

Using only field widths to provide for tabulation, as with a format like "%8d%8d%8d" for three integers in three 8-character columns, will not guarantee that field separation will be retained if large numbers occur in the data. Loss of field separation can easily lead to corrupt output. In systems which encourage the use of programs as building blocks in scripts, such corrupt data can often be forwarded into and corrupt further processing, regardless of whether the original programmer expected the output would only be read by human eyes. Such problems can be eliminated by including explicit delimiters, even spaces, in all tabular output formats. Simply changing the dangerous example from before to " %7d %7d %7d" addresses this, formatting identically until numbers become larger, but then explicitly preventing them from becoming merged on output due to the explicitly included spaces. Similar strategies apply to string data.

Read more about this topic:  Printf Format String

Famous quotes containing the words risks of, risks, field, width, explicit and/or output:

    The question is whether personal freedom is worth the terrible effort, the never-lifted burden and risks of self-reliance.
    Rose Wilder Lane (1886–1968)

    There are risks which are not acceptable: the destruction of humanity is one of them.
    Friedrich Dürrenmatt (1921–1990)

    She is as in a field a silken tent
    At midday when a sunny summer breeze
    Has dried the dew and all its ropes relent,
    Robert Frost (1874–1963)

    Newly stumbling to and fro
    All they find, outside the fold,
    Is a wretched width of cold.
    Philip Larkin (1922–1986)

    Like dreaming, reading performs the prodigious task of carrying us off to other worlds. But reading is not dreaming because books, unlike dreams, are subject to our will: they envelop us in alternative realities only because we give them explicit permission to do so. Books are the dreams we would most like to have, and, like dreams, they have the power to change consciousness, turning sadness to laughter and anxious introspection to the relaxed contemplation of some other time and place.
    Victor Null, South African educator, psychologist. Lost in a Book: The Psychology of Reading for Pleasure, introduction, Yale University Press (1988)

    Lizzie Borden took an axe
    And gave her mother forty whacks;
    When she saw what she had done,
    She gave her father forty-one.
    —Anonymous. Late 19th century ballad.

    The quatrain refers to the famous case of Lizzie Borden, tried for the murder of her father and stepmother on Aug. 4, 1892, in Fall River, Massachusetts. Though she was found innocent, there were many who contested the verdict, occasioning a prodigious output of articles and books, including, most recently, Frank Spiering’s Lizzie (1985)