fork download
  1. void radix_Print(unsigned int n, int base){
  2. if (n >= base) radix_Print(n / base, base);
  3. print_char("0123456789ABCDEF"[n % base]);
  4. }
  5. void radix_print(unsigned int n, int base){
  6. if (n >= base) radix_print(n / base, base);
  7. print_char("0123456789abcdef"[n % base]);
  8. }
  9.  
  10.  
  11.  
  12.  
  13. int myprintf(char *fmt, ...){
  14.  
  15. char *argx = ((char*)&fmt) + ((sizeof(fmt) + 3) / 4) * 4;
  16. //char *argx = ((char*)&fmt) + 4;
  17. int i1,j;
  18. char *c1;
  19. float f1;
  20.  
  21. while(*fmt){
  22.  
  23. if(*fmt == '%'){
  24. fmt++;
  25. switch(*fmt){
  26. case 'd':
  27.  
  28. i1 = *(int*)argx;
  29.  
  30. print_int(i1);
  31. argx += ((sizeof(int) + 3) / 4) * 4;
  32.  
  33. break;
  34.  
  35. case 's':
  36.  
  37. c1 = *(char**)argx;
  38.  
  39. print_string(c1);
  40. argx += ((sizeof(char*)+3)/4)*4;
  41.  
  42. break;
  43.  
  44. case 'c':
  45. c1 = *(char**)argx;
  46.  
  47. print_char(c1);
  48. argx += ((sizeof(char*)+3)/4)*4;
  49.  
  50. break;
  51.  
  52. case '%':
  53. print_char('%');
  54. break;
  55.  
  56.  
  57. case 'x':
  58. i1 = *(int*)argx;
  59. radix_print(i1, 16);
  60. argx += ((sizeof(int) + 3) / 4) * 4;
  61. break;
  62.  
  63. case 'X':
  64. i1 = *(int*)argx;
  65. radix_Print(i1, 16);
  66. argx += ((sizeof(int) + 3) / 4) * 4;
  67. break;
  68.  
  69. case 'o':
  70. i1 = *(int*)argx;
  71. radix_print(i1, 8);
  72. argx += ((sizeof(int) + 3) / 4) * 4;
  73. break;
  74. /*
  75.   case 'e':
  76.   f1 = *(float*)argx;
  77.   if(i1>=0){
  78.   for(j=0;;j++){
  79. f1 = f1 / 10;
  80.   if(i1<=0){break;}
  81.   }
  82. }
  83.   else
  84. for(j=0;;j++){
  85.   f1 = f1 * 10;
  86.   if(i1>=0){break;}
  87.   j=-j;
  88. }
  89.  
  90.   print_float(f1);
  91.   print_char('e');
  92. if(j>=0){print_char('+');}
  93.   print_int(j);
  94.  
  95. argx += ((sizeof(float*) + 3) / 4) * 4;
  96.  
  97.   break;
  98. */
  99.  
  100. }
  101. }
  102.  
  103. else{
  104. print_char(*fmt);
  105. }
  106. fmt++;
  107. }
  108.  
  109. }
  110.  
  111.  
  112.  
  113.  
  114. int main(){
  115.  
  116. int a = 15;
  117. int c = 11;
  118. char b[] = "ab12cd";
  119.  
  120. myprintf("%d to %o\n", c, c);
  121. myprintf("%d to %X\n", c, c);
  122. myprintf("%d to %x\n", c, c);
  123.  
  124. return 0;
  125. }
  126.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.c: In function ‘radix_Print’:
prog.c:3:3: warning: implicit declaration of function ‘print_char’ [-Wimplicit-function-declaration]
   print_char("0123456789ABCDEF"[n % base]);
   ^
prog.c: In function ‘myprintf’:
prog.c:30:9: warning: implicit declaration of function ‘print_int’ [-Wimplicit-function-declaration]
         print_int(i1);
         ^
prog.c:39:9: warning: implicit declaration of function ‘print_string’ [-Wimplicit-function-declaration]
         print_string(c1);
         ^
prog.c:19:9: warning: unused variable ‘f1’ [-Wunused-variable]
   float f1;
         ^
prog.c:17:10: warning: unused variable ‘j’ [-Wunused-variable]
   int i1,j;
          ^
prog.c: In function ‘main’:
prog.c:118:8: warning: unused variable ‘b’ [-Wunused-variable]
   char b[] = "ab12cd";
        ^
prog.c:116:7: warning: unused variable ‘a’ [-Wunused-variable]
   int a = 15;
       ^
prog.c: In function ‘myprintf’:
prog.c:109:1: warning: control reaches end of non-void function [-Wreturn-type]
 }
 ^
/home/ny1NSi/ccgXLDph.o: In function `myprintf':
prog.c:(.text+0xf0): undefined reference to `print_char'
prog.c:(.text+0xfc): undefined reference to `print_char'
prog.c:(.text+0x149): undefined reference to `print_string'
prog.c:(.text+0x161): undefined reference to `print_int'
prog.c:(.text+0x179): undefined reference to `print_char'
/home/ny1NSi/ccgXLDph.o: In function `radix_Print':
prog.c:(.text+0x3a): undefined reference to `print_char'
/home/ny1NSi/ccgXLDph.o: In function `radix_print':
prog.c:(.text+0x7a): undefined reference to `print_char'
collect2: error: ld returned 1 exit status
stdout
Standard output is empty