|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
- #include <stdio.h>
- #include <string.h>
- #include <stdarg.h>
- #include <math.h>
- int myprintf(const char* format,...)
- {
- int i=0,temp,example,example1,j=0,zifushu=0,chushu1,chushu2;
- char a;
- char s;
- va_list vap;
- va_start(vap,format);
-
- while(1)
- {
- if(*(format+i)=='\0')
- break;
- if(*(format+i)=='%')
- {
- while(1)
- {
- if(*(format+i+1)=='d')
- {
- temp=va_arg(vap,int);
- example=temp;
- while(1)
- {
- if(temp==0)
- {
- j=1;
- break;
- }
- if(example==0)
- break;
- j++;
- example=example/10;
- }
- example=temp;
- if(temp>=0)
- {
- while(1)
- {
- if(j==0)
- break;
- chushu1=pow(10,j);
- chushu2=pow(10,j-1);
- example1=example%chushu1/chushu2;
- a=example1+48;
- putchar(a);
- j--;
- zifushu++;
- }
- }
- else
- {
- putchar('-');
- while(1)
- {
- if(j==0)
- break;
- chushu1=pow(10,j);
- chushu2=pow(10,j-1);
- example1=example%chushu1/chushu2;
- a=48-example1;
- putchar(a);
- j--;
- zifushu++;
- }
- }
- }
- else if(*(format+i+1)=='c')
- {
- s=va_arg(vap,char);
- putchar(s);
- }
- i=i+2;
- if(*(format+i)!='%')
- break;
- }
- }
- putchar(*(format+i));
- i++;
- zifushu++;
- }
- return zifushu;
- }
-
- int main()
- {
- myprintf("%d%c",-1234,'s');
- }
复制代码
1 0 E:\Dev-Cpp\MinGW64\lib\gcc\x86_64-w64-mingw32\4.9.2\include\stdarg.h In file included from E:/Dev-Cpp/MinGW64/lib/gcc/x86_64-w64-mingw32/4.9.2/include/stdarg.h
3 C:\Users\DRD\Desktop\c\未命名51.cpp from C:\Users\DRD\Desktop\c\未命名51.cpp
C:\Users\DRD\Desktop\c\未命名51.cpp In function 'int myprintf(const char*, ...)':
73 18 C:\Users\DRD\Desktop\c\未命名51.cpp [Warning] 'char' is promoted to 'int' when passed through '...'
73 18 C:\Users\DRD\Desktop\c\未命名51.cpp [Note] (so you should pass 'int' not 'char' to 'va_arg')
73 18 C:\Users\DRD\Desktop\c\未命名51.cpp [Note] if this code is reached, the program will abort
|
|