From d8b84c3699f6b0c35225cbd0ffb3e8af8c08d8ad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafa=C5=82=20-rsm-=20Marek?= Date: Fri, 24 May 2024 15:07:27 +0200 Subject: [PATCH] Exerc 4_14. --- .../4_14.swap_macro/Makefile | 3 +++ .../4_14.swap_macro/main.c | 17 +++++++++++++++++ .../4_14.swap_macro/swap.h | 11 +++++++++++ .../4_14.swap_macro/tests/t0.tin | 0 .../4_14.swap_macro/tests/t0.tout | 2 ++ 5 files changed, 33 insertions(+) create mode 100644 chapter_4.functions_progr_structure/4_14.swap_macro/Makefile create mode 100644 chapter_4.functions_progr_structure/4_14.swap_macro/main.c create mode 100644 chapter_4.functions_progr_structure/4_14.swap_macro/swap.h create mode 100644 chapter_4.functions_progr_structure/4_14.swap_macro/tests/t0.tin create mode 100644 chapter_4.functions_progr_structure/4_14.swap_macro/tests/t0.tout diff --git a/chapter_4.functions_progr_structure/4_14.swap_macro/Makefile b/chapter_4.functions_progr_structure/4_14.swap_macro/Makefile new file mode 100644 index 0000000..a059b35 --- /dev/null +++ b/chapter_4.functions_progr_structure/4_14.swap_macro/Makefile @@ -0,0 +1,3 @@ +BINARY=swap_macro + +include ../../Makefile.exerc diff --git a/chapter_4.functions_progr_structure/4_14.swap_macro/main.c b/chapter_4.functions_progr_structure/4_14.swap_macro/main.c new file mode 100644 index 0000000..6739166 --- /dev/null +++ b/chapter_4.functions_progr_structure/4_14.swap_macro/main.c @@ -0,0 +1,17 @@ +# include +# include "swap.h" + +int main () +{ + char c0 = '0', c1 = '1'; + int i0 = 10, i1 = 222; + + printf("char: '%c', '%c' => '", c0, c1); + swap(char, c0, c1); + printf("%c', '%c'\n", c0, c1); + printf("int: %d, %d => ", i0, i1); + swap(int, i0, i1); + printf("%d, %d\n", i0, i1); + + return 0; +} diff --git a/chapter_4.functions_progr_structure/4_14.swap_macro/swap.h b/chapter_4.functions_progr_structure/4_14.swap_macro/swap.h new file mode 100644 index 0000000..13b60de --- /dev/null +++ b/chapter_4.functions_progr_structure/4_14.swap_macro/swap.h @@ -0,0 +1,11 @@ +# ifndef SWAP_H +# define SWAP_H + +# define swap(T, X, Y) \ + { \ + T c = X; \ + X = Y; \ + Y = c; \ + }; \ + +# endif diff --git a/chapter_4.functions_progr_structure/4_14.swap_macro/tests/t0.tin b/chapter_4.functions_progr_structure/4_14.swap_macro/tests/t0.tin new file mode 100644 index 0000000..e69de29 diff --git a/chapter_4.functions_progr_structure/4_14.swap_macro/tests/t0.tout b/chapter_4.functions_progr_structure/4_14.swap_macro/tests/t0.tout new file mode 100644 index 0000000..cf6c517 --- /dev/null +++ b/chapter_4.functions_progr_structure/4_14.swap_macro/tests/t0.tout @@ -0,0 +1,2 @@ +char: '0', '1' => '1', '0' +int: 10, 222 => 222, 10