欧美性猛交XXXX免费看蜜桃,成人网18免费韩国,亚洲国产成人精品区综合,欧美日韩一区二区三区高清不卡,亚洲综合一区二区精品久久

打開(kāi)APP
userphoto
未登錄

開(kāi)通VIP,暢享免費電子書(shū)等14項超值服

開(kāi)通VIP
實(shí)現自己的printf函數

http://blog.csdn.net/zy799894671/article/details/7761038

2012

my_printf.h:

[csharp] view plain copy
  1. extern void my_printf(const char *format,...);  


 

my_printf.c:

[csharp] view plain copy
  1. #include "my_printf.h"  
  2. #include "stdarg.h"  
  3. /********************************************************** 
  4.  
  5. ***********************************************************/  
  6. void printch(const char ch)  
  7. {  
  8.     putchar(ch);  
  9. }  
  10. /********************************************************** 
  11.  
  12. ***********************************************************/  
  13. void printint(const int dec)  
  14. {  
  15.     if(dec == 0)  
  16.     {  
  17.         return;  
  18.     }  
  19.     printint(dec / 10);  
  20.     putchar((char)(dec % 10 + '0'));  
  21. }  
  22. /********************************************************** 
  23.  
  24. ***********************************************************/  
  25. void printstr(const char *ptr)  
  26. {  
  27.     while(*ptr)  
  28.     {  
  29.         putchar(*ptr);  
  30.     ptr++;  
  31.     }  
  32. }  
  33. /********************************************************** 
  34.  
  35. ***********************************************************/  
  36. void printfloat(const float flt)  
  37. {  
  38.     int tmpint = (int)flt;  
  39.     int tmpflt = (int)(100000 * (flt - tmpint));  
  40.     if(tmpflt % 10 >= 5)  
  41.     {  
  42.         tmpflt = tmpflt / 10 + 1;  
  43.     }  
  44.     else  
  45.     {  
  46.         tmpflt = tmpflt / 10;  
  47.     }  
  48.     printint(tmpint);  
  49.     putchar('.');  
  50.     printint(tmpflt);  
  51.   
  52. }  
  53. /********************************************************** 
  54.  
  55. ***********************************************************/  
  56. void my_printf(const char *format,...)  
  57. {  
  58.     va_list ap;  
  59.     va_start(ap,format);  
  60.     while(*format)  
  61.     {  
  62.         if(*format != '%')  
  63.     {  
  64.             putchar(*format);  
  65.         format++;  
  66.     }  
  67.     else  
  68.     {  
  69.         format++;  
  70.         switch(*format)  
  71.         {  
  72.             case 'c':  
  73.             {  
  74.                 char valch = va_arg(ap,int);  
  75.             printch(valch);  
  76.             format++;  
  77.             break;  
  78.             }  
  79.             case 'd':  
  80.             {  
  81.                 int valint = va_arg(ap,int);  
  82.             printint(valint);  
  83.             format++;  
  84.             break;  
  85.             }  
  86.         case 's':  
  87.         {  
  88.             char *valstr = va_arg(ap,char *);  
  89.             printstr(valstr);  
  90.             format++;  
  91.             break;  
  92.         }  
  93.         case 'f':  
  94.         {  
  95.             float valflt = va_arg(ap,double);  
  96.             printfloat(valflt);  
  97.             format++;  
  98.             break;  
  99.         }  
  100.         default:  
  101.         {  
  102.             printch(*format);  
  103.             format++;  
  104.         }  
  105.         }  
  106.         va_end(ap);  
  107.     }  
  108.     }  
  109. }  
  110. /********************************************************** 
  111.  
  112. ***********************************************************/  
  113. int main()  
  114. {  
  115.     char ch = 'A';  
  116.     char *str = "holle world";  
  117.     int dec = 1234;  
  118.     float flt = 1234.3456789;   
  119.     my_printf("str = %s,dec = %d,ch = %c,flt = %f\n",str,dec,ch,flt);  
  120.     return 0;  
  121. }  

編譯一下,運行一下,ok了。

(注:float型我這能輸出小數點(diǎn)后4位,第5位四舍五入了)

本站僅提供存儲服務(wù),所有內容均由用戶(hù)發(fā)布,如發(fā)現有害或侵權內容,請點(diǎn)擊舉報。
打開(kāi)APP,閱讀全文并永久保存 查看更多類(lèi)似文章
猜你喜歡
類(lèi)似文章
bash Linux 文件判斷,if
c51 函數庫函數 STDIO.H:一般I/O函數
短小精悍,最全介紹,C語(yǔ)言輸入輸出printf、scanf
扒一扒中斷為什么不能調printf
C的可變參數
C語(yǔ)言 sscanf用法詳解
更多類(lèi)似文章 >>
生活服務(wù)
分享 收藏 導長(cháng)圖 關(guān)注 下載文章
綁定賬號成功
后續可登錄賬號暢享VIP特權!
如果VIP功能使用有故障,
可點(diǎn)擊這里聯(lián)系客服!

聯(lián)系客服

欧美性猛交XXXX免费看蜜桃,成人网18免费韩国,亚洲国产成人精品区综合,欧美日韩一区二区三区高清不卡,亚洲综合一区二区精品久久