标签:va_end for r++ int printf tchar stat hex tar
1 void PrintInt(int i) 2 { 3 int sign = i>0 ? 0 : 1; 4 u8 s[10]; 5 int cnt=0; 6 if(sign) 7 { 8 StatlWrite((u8 *)‘-‘,1); 9 i = -i; 10 } 11 int ten = i%10; 12 while(i) 13 { 14 s[cnt] = ten+‘0‘; 15 cnt++; 16 i /= 10; 17 ten = i%10; 18 } 19 while(cnt>0) 20 { 21 StatlWrite(&s[--cnt],1); 22 } 23 } 24 25 void PrintStr(char* str) 26 { 27 while(*str != ‘ ‘) 28 StatlWrite((u8 *)str++,1); 29 } 30 31 void PrintChar(u8 *c) 32 { 33 StatlWrite((u8 *)c,1); 34 } 35 36 37 38 int myprintf (char *format, ...) 39 { 40 va_list arg; 41 static char stepflag =0; 42 int Decdate; 43 char Hex; 44 char* String; 45 46 va_start (arg, format); 47 do 48 { 49 if(*format != ‘%‘) 50 { 51 if(stepflag==1) 52 { 53 stepflag = 0; 54 format++; 55 } 56 else 57 { 58 PrintChar((u8*)format++); 59 } 60 } 61 else 62 { 63 stepflag = 1; 64 switch(*(++format)) 65 { 66 case(‘d‘): 67 Decdate = va_arg(arg,int); 68 PrintInt(Decdate); 69 break; 70 case(‘c‘): 71 Hex = va_arg(arg,int); 72 //PrintChar(Hex); 73 break; 74 case(‘s‘): 75 String = va_arg(arg,char *); 76 //PrintStr(String); 77 break; 78 default: 79 //myprintf("I need relax."); 80 break; 81 } 82 } 83 } 84 while(*format != ‘\0‘); 85 86 va_end (arg); 87 return 1; 88 }
标签:va_end for r++ int printf tchar stat hex tar
原文地址:https://www.cnblogs.com/liushuhe1990/p/9608981.html