my_printf
来源:互联网 发布:python 调用hanlp分词 编辑:程序博客网 时间:2024/05/31 19:21
#include <stdio.h>
#include <stdarg.h>
#include <stdlib.h>
#include <math.h>
void myprintf(const char *format, ...)
{
va_list ap;
char c;
va_start(ap, format);
while(c = *format++)
{
switch(c)
{
case 'c': {
char ch = va_arg(ap, int);
putchar(ch);
break;
}
case 's':
{
char *p = va_arg(ap, char *);
fputs(p, stdout);
break;
}
case 'd':
{
int a = va_arg(ap, int);
int len, i, b;
b = a;
b = abs(b);
while (b)
{
b = b / 10;
len++;
}
if(a < 0)
{ len++;}
char f[len+1];
f[len] = '/0';
b = a;
b = abs(b);
for(i = len -1; i >= 0; i--)
{
f[i] = b % 10 + '0' ;
b = b / 10;
}
{ if(a < 0)
f[0] = '-';}
puts(f);
len = 0;
break;
}
default :
putchar(c);
}
}
va_end(ap);
}
int main(void)
{
char c = 'I';
myprintf("d/td/tc/ts/n", 40, -2, c, "hello");
return 0;
}
- my_printf
- 实现My_printf
- printf的实现,my_printf
- my_printf的实现小例子
- 【c语言】 模拟实现printf,要求功能: my_printf("dc\ts\ndc\ndc\ts!", ...)
- C语言:模拟实现printf函数——my_printf函数哦
- 模拟实现一个printf,函数可以实现my_printf("s ccc.","hello", 'n','i','h','a','o');//遇到s表示字符串
- 新项目组.
- log4cpp 学习过程(四) ---- log4cpp在VS2003上的编译
- Struts2拦截器--异常拦截器
- C语言学习计划
- bitset 用法整理!
- my_printf
- Oracle 分析函数
- 大学生入职笔试题
- Eclipse RCP入门学习最佳手册
- 战争磨盘二.以牙还牙
- SQL2005/2008:错误233的解决方案
- rand 和 srand产生随机数
- Spring2.5中基于注释的IoC
- DataGrid,DataList,Repeater等数据访问控件的区别及总结