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)

    The amount of it is, if a man is alive, there is always danger that he may die, though the danger must be allowed to be less in proportion as he is dead-and-alive to begin with. A man sits as many risks as he runs.
    Henry David Thoreau (1817–1862)

    And they wonder, as waiting the long years through
    In the dust of that little chair,
    What has become of our Little Boy Blue,
    Since he kissed them and put them there.
    —Eugene Field (1850–1895)

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

    ... the Ovarian Theory of Literature, or, rather, its complement, the Testicular Theory. A recent camp follower ... of this explicit theory is ... Norman Mailer, who has attributed his own gift, and the literary gift in general, solely and directly to the possession of a specific pair of organs. One writes with these organs, Mailer has said ... and I have always wondered with what shade of ink he manages to do it.
    Cynthia Ozick (b. 1928)

    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)