// filename:c2011-7-21-6-1-ex.c // original examples and/or notes: // (c) ISO/IEC JTC1 SC22 WG14 N1570, April 12, 2011 // C2011 7.21.6.1 The fprintf function // compile and output mechanism: // (c) Ogawa Kiyoshi, kaizen@gifu-u.ac.jp, December.29, 2013 // compile errors and/or wornings: // (c) Apple LLVM version 4.2 (clang-425.0.27) (based on LLVM 3.2svn) // Target: x86_64-apple-darwin11.4.2 //Thread model: posix // (c) LLVM 2003-2009 University of Illinois at Urbana-Champaign. #include #include #include int main(void) { // Example 1 /* ... */ char *weekday, *month; // pointers to strings int day, hour, min; weekday = "Monday",month="December", day=30, hour=23, min=34; fprintf(stdout, "%s, %s %d, %.2d:%.2d\n", weekday, month, day, hour, min); fprintf(stdout, "pi = %.5f\n", 4 * atan(1.0)); // Example 2static wchar_t wstr[] = L" X Yabc Z W"; static wchar_t wstr[] = L" X Yabc Z W"; fprintf(stdout, "|1234567890123|\n"); fprintf(stdout, "|%13ls|\n", wstr); fprintf(stdout, "|%-13.9ls|\n", wstr); fprintf(stdout, "|%13.10ls|\n", wstr); fprintf(stdout, "|%13.11ls|\n", wstr); fprintf(stdout, "|%13.15ls|\n", &wstr[2]); fprintf(stdout, "|%13lc|\n", (wint_t) wstr[5]); return printf("7.21.6.1 The fprintf function \n"); } // output may be //Monday, December 30, 23:34 //pi = 3.14159 //|1234567890123| //| X Yabc Z W| //| X Yabc Z | //| X Yabc Z | //| X Yabc Z W| //| Yabc Z W| //| b| //7.21.6.1 The fprintf function