Implements a simplified printf function that can process formats such as % d, % F, % s, and % C.
/*************************************** * *********************************> File Name: permutation. c> created time: tuesday, June 17, 2014, 34 seconds ******************************** **************************************** /# include <stdio. h> # include <stdarg. h> # include <stdlib. h> // output the normal string int printstr (char const * Str) {int Len = 0; while (* Str! = '\ 0') {putchar (* STR ++); Len ++;} return Len ;}// description, a simplified printf function, this function is in the format of % d, % C, % F, and % S. Other formats are undefined. Int myprintf (char const * format ,...) {int Len = 0; int sublen; va_list vlist; va_start (vlist, format); // obtain the first address of the first parameter while (* Format! = '\ 0') {char data [50]; int sublen = 1; if (* Format ++ =' % ') {If (* format = 'D') {int d = va_arg (vlist, INT); char dd [10]; ITOA (D, DD, 10 ); sublen = printstr (dd);} else if (* format = 'C') {char c = va_arg (vlist, char); putchar (c); sublen = 1 ;} else if (* format = 's') {char * STR = va_arg (vlist, char *); sublen = printstr (STR );} else if (* format = 'F') {double D = va_arg (vlist, double); char dd [20]; gcvt (D, 10, DD ); sublen = printstr (dd);} format ++; printf ("\ n");} Len + = sublen;} va_end (vlist); Return Len;} int main () {int num = myprintf ("% d % C % S % F", 4, 'A', "1213", 3.14); printf ("length of output characters (space, except carriage return): % d \ n ", num); Return 0 ;}