标签:模拟实现printf 要求功能:print("ccc\ts!" 'b' 'i' 't' "welcome to you");
#define _CRT_SECURE_NO_WARNINGS 1 #include <stdio.h> #include <stdlib.h> #include <stdarg.h> int my_printf(const char *fmt, ...) { const char *s; char c; va_list ap;//参数列表 va_start(ap, fmt);//取的fmt指针给ap while (*fmt) { /*if (*fmt != ‘s‘ || *fmt != ‘c‘) { putchar(*fmt++); continue; }*/ switch (*fmt) { case ‘s‘: s = va_arg(ap, const char *);//取参数 for (; *s; s++)//通过循环,打印字符串内容 { putchar(*s); } break; case ‘c‘: c = va_arg(ap, char); putchar(c); break; default: putchar(*fmt); break; } fmt++; } va_end(ap);//置0 } int main() { char a = ‘b‘; my_printf("ccc\ts!", ‘b‘, ‘i‘, ‘t‘, "welcome to you"); system("pause"); return 0; }
C语言:模拟实现printf,要求功能:print("ccc\ts!",'b','i','t',"welcome to you");
标签:模拟实现printf 要求功能:print("ccc\ts!" 'b' 'i' 't' "welcome to you");
原文地址:http://10740184.blog.51cto.com/10730184/1711904