程序代码:
#include<stdio.h>
int myprintf( const char*format, ...)
{
int *p;
char c;
p=(int*)&format;
while((c=*format++)!='\0')
{
if(c!='%')
{
putchar(c);
continue;
}
else
{
c=*format++;
if(c=='d')
{
int value;
p++;
value=*p;
printf("%d",value);
}
if(c=='x')
{
int value;
p++;
value=*p;
printf("%d",value);
}
}
}
return 0;
}
int main(void)
{
myprintf("a=%d,b=%x\n",700,200,100);
//test(100,200,300,400);
return 0;
}
/*
int test(int a,int b,int c,int d)
{
int *p;
p=&a;
printf("p=%d\n",*p);
printf("a=%d\n",*p);
p--;
printf("b=%d\n",*p);
p--;
printf("c=%d\n",*p);
p--;
printf("d=%d\n",*p);
printf("&a=%p\n",&a);
printf("&b=%p\n",&b);
printf("&c=%p\n",&c);
printf("&d=%p\n",&d);
return 0;
}
*/
我一开始用来测试的test函数发现就能正确输出啊