c语言:模拟实现printf,要求功能:print("ccc\ts!",'b','i','t',"welcome to you");
来源:互联网 发布:武尊少林源码 编辑:程序博客网 时间:2024/05/24 06:42
程序:
#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;
}
结果:
bit welcome to you!请按任意键继续. . .
本文出自 “岩枭” 博客,请务必保留此出处http://yaoyaolx.blog.51cto.com/10732111/1712001
0 0
- c语言:模拟实现printf,要求功能:print("ccc\ts!",'b','i','t',"welcome to you");
- C语言:模拟实现printf,要求功能:print("ccc\ts!",'b','i','t',"welcome to you");
- 【c语言】 模拟实现printf,要求功能: my_printf("dc\ts\ndc\ndc\ts!", ...)
- 使用可变参数列表实现print("s\tc\n","bit-tech",'w');
- String s = "a" + "b" + "c" + "d" + "
- 【Vegas转载】RMAN的"rman: can't open target"错误
- 【Vegas转载】RMAN的"rman: can't open target"错误
- 【ERROR】---Error executing "adb devices":ADB server didn't ACK
- java.lang.ClassNotFoundException: Didn't find class "*****Activity" on path: /data/ap
- [中文]React:"don't fuck it up like Google did with Angular"
- 002-Fatal error in launcher: Unable to create process using '""
- reason: '-[UITableViewController loadView] loaded the "GWHomeViewController" nib but didn't get a UITableView.
- extern "c"
- 关于 '<a[^>]+href=["\'](.*?)["\']' 的解释
- [转载]ubuntu bash '/bin/sh: Syntax error: "(" unexpected'错误解决
- " " ' '
- JS:"全选"功能实现(checkbox)
- YOU SAY "THE RULE IS HERE",BUT I SAY "WHY?"
- 高并发 php uniqid 不重复唯一标识符生成方案
- 3.大概了解Tornado框架的设计模型
- c语言;求Sn=a+aa+aaa+aaaa+aaaaa的前5项之和 其中a是一个数字 例如:2+22+222+2222+22222
- c语言:编写冒泡排序,排序一个整形数组(从小到大)
- 懒续
- c语言:模拟实现printf,要求功能:print("ccc\ts!",'b','i','t',"welcome to you");
- 2.0.0hive整合1.2.1hbase的api遇到的连接问题
- c语言:常用各种头文件的作用,如:#include <stdlib.h>
- c语言:3种方法;求出0~999之间的所有“水仙花数”并输出。
- c语言:使用main函数的参数,实现一个整数计算器
- Logcat调试信息
- c语言:有一个分数序列: 2/1+3/2+5/3+8/5+13/8+… 求出这个数列前 20 项的和
- c语言:一个球从 100 米高的自由落下,每次落地后反跳回原高度的一半
- c语言:猴子吃桃问题