/************************************************************************ * * * Copyright Digital Equipment Corporation 1998. All rights reserved. * * * * Restricted Rights: Use, duplication, or disclosure by the U.S. * * Government is subject to restrictions as set forth in subparagraph * * (c) (1) (ii) of DFARS 252.227-7013, or in FAR 52.227-19, or in FAR * * 52.227-14 Alt. III, as applicable. * * * * This software is proprietary to and embodies the confidential * * technology of Digital Equipment Corporation. Possession, use, or * * copying of this software and media is authorized only pursuant to a * * valid written license from Digital or an authorized sublicensor. * * * ************************************************************************/ /* chap_2_out_conv.c */ /* This program uses the printf function to print the */ /* various conversion specifications and their affect */ /* on the output. */ /* Include the proper header files in case printf has */ /* to return EOF. */ #include #include #include #define WIDE_STR_SIZE 20 main() { double val = 123345.5; char c = 'C'; int i = -1500000000; char *s = "thomasina"; wchar_t wc; wchar_t ws[WIDE_STR_SIZE]; /* Produce a wide character and a wide character string */ if (mbtowc(&wc, "W", 1) == -1) { perror("mbtowc"); exit(EXIT_FAILURE); } if (mbstowcs(ws, "THOMASINA", WIDE_STR_SIZE) == -1) { perror("mbstowcs"); exit(EXIT_FAILURE); } /* Print the specification code, a colon, two tabs, and the */ /* formatted output value delimited by the angle bracket */ /* characters (<>). */ printf("%%9.4f:\t\t<%9.4f>\n", val); printf("%%9f:\t\t<%9f>\n", val); printf("%%9.0f:\t\t<%9.0f>\n", val); printf("%%-9.0f:\t\t<%-9.0f>\n\n", val); printf("%%11.6e:\t\t<%11.6e>\n", val); printf("%%11e:\t\t<%11e>\n", val); printf("%%11.0e:\t\t<%11.0e>\n", val); printf("%%-11.0e:\t\t<%-11.0e>\n\n", val); printf("%%11g:\t\t<%11g>\n", val); printf("%%9g:\t\t<%9g>\n\n", val); printf("%%d:\t\t<%d>\n", c); printf("%%c:\t\t<%c>\n", c); printf("%%o:\t\t<%o>\n", c); printf("%%x:\t\t<%x>\n\n", c); printf("%%d:\t\t<%d>\n", i); printf("%%u:\t\t<%u>\n", i); printf("%%x:\t\t<%x>\n\n", i); printf("%%s:\t\t<%s>\n", s); printf("%%-9.6s:\t\t<%-9.6s>\n", s); printf("%%-*.*s:\t\t<%-*.*s>\n", 9, 5, s); printf("%%6.0s:\t\t<%6.0s>\n\n", s); printf("%%C:\t\t<%C>\n", wc); printf("%%S:\t\t<%S>\n", ws); printf("%%-9.6S:\t\t<%-9.6S>\n", ws); printf("%%-*.*S:\t\t<%-*.*S>\n", 9, 5, ws); printf("%%6.0S:\t\t<%6.0S>\n\n", ws); }