fork download
  1. //(c)Terminator
  2. #include <stdio.h>
  3. #define N 6
  4.  
  5. #define tpl_array_rev(pfx, type) \
  6. void array_rev##pfx(type* f, type* l){\
  7. type t;\
  8. type* a = f, *b = l - 1;\
  9. while(a < b){\
  10. t = *a;\
  11. *a = *b;\
  12. *b = t;\
  13. ++a;\
  14. --b;\
  15. }\
  16. }
  17.  
  18. #define tpl_array_print(pfx, fmt, type) \
  19. void print_array##pfx(FILE* hout, const type* f, const type* l){\
  20. for(; f != l; ++f){\
  21. fprintf(hout, fmt, *f);\
  22. fputc(' ', hout);\
  23. }\
  24. fputc('\n', hout);\
  25. }
  26.  
  27. tpl_array_rev(i, int)
  28. tpl_array_rev(d, double)
  29. tpl_array_rev(c, char)
  30.  
  31. tpl_array_print(i, "%d", int)
  32. tpl_array_print(d, "%lf", double)
  33. tpl_array_print(c, "%c", char)
  34.  
  35.  
  36.  
  37. int main(void){
  38. char str[] = "ABCDEF";
  39. int iarr[] = { 1, 2, 3, 4, 5, 6, };
  40. double darr[] = { 0.1, 0.2, 0.3, 0.4, 0.5, 0.6 };
  41.  
  42. print_arrayc(stdout, str, str + N);
  43. array_revc(str, str + N);
  44. print_arrayc(stdout, str, str + N);
  45. putchar('\n');
  46.  
  47. print_arrayi(stdout, iarr, iarr + N);
  48. array_revi(iarr, iarr + N);
  49. print_arrayi(stdout, iarr, iarr + N);
  50. putchar('\n');
  51.  
  52. print_arrayd(stdout, darr, darr + N);
  53. array_revd(darr, darr + N);
  54. print_arrayd(stdout, darr, darr + N);
  55. return 0;
  56. }
  57.  
Success #stdin #stdout 0s 2292KB
stdin
Standard input is empty
stdout
A B C D E F 
F E D C B A 

1 2 3 4 5 6 
6 5 4 3 2 1 

0.100000 0.200000 0.300000 0.400000 0.500000 0.600000 
0.600000 0.500000 0.400000 0.300000 0.200000 0.100000