The UNIX Operating System

TOP

UP


Ray Seyfarth

ORCA


Computer Science

COST

USM




print and printf


  • print does default formatting
    commas between printed items result in spaces

  • printf is like C's printf

  • printf "%d", n
    prints n as a decimal with no new-line

  • %3d = decimal width 3

  • %4x = hexadecimal

  • %c = character, either a number is converted or first character

  • %12s = string width 12 (may overflow if the string is longer)

  • %12.12s = string width 12 (no overflow)

  • %12.16s = string width 12 to 16

  • %8.3f = floating point width 8 with 3 digits for the fraction

  • Placing - before the width means left justify


University of Southern Mississippi
Ray.Seyfarth@usm.edu
Updated 15:45 Sep 13, 2006