diff --git a/ch_04/exercise_04-01/main.c b/ch_04/exercise_04-01/main.c index 0ce0e21..184b05b 100644 --- a/ch_04/exercise_04-01/main.c +++ b/ch_04/exercise_04-01/main.c @@ -15,7 +15,7 @@ int main() { - char s[] = "this is not the end, but it might as well be.The time is nigh. The end will befall all of us. The end.\0"; + char s[] = "this is not the end, but it might as well be. The end will befall all of us. The end.\0"; char t[] = "end\0"; printf("Searching for string: %s\nIn: %s\n", t, s); diff --git a/ch_04/exercise_04-14/main.c b/ch_04/exercise_04-14/main.c new file mode 100644 index 0000000..55073e3 --- /dev/null +++ b/ch_04/exercise_04-14/main.c @@ -0,0 +1,42 @@ +/* + * + * Exercise 4-14. Define a macro swap(t,x,y) that interchanges two arguments of type t. + * + * Author: Kun Deng + */ + +#include + +// Macro definition +#define swap(t, x, y) do \ +{ \ + t tmp = x; \ + x = y; \ + y = tmp; \ +} while(0) + + +void print_pair(const int x, const int y, const char *message) +{ + printf("%s: x = %d and y = %d\n", message, x, y); +} + + +int main() +{ + int x_int = 10, y_int = 25; + + print_pair(x_int, y_int, "Before"); + + swap(int, x_int, y_int); + + print_pair(x_int, y_int, "After"); + + float x_double = 99.99, y_double = 8.55; + + print_pair(x_double, y_double, "Before"); + swap(float, x_double, y_double); + print_pair(x_double, y_double, "After"); + + return 0; +} diff --git a/ch_04/exercise_04-14/main_template.c b/ch_04/exercise_04-14/main_template.c deleted file mode 100644 index 2604c61..0000000 --- a/ch_04/exercise_04-14/main_template.c +++ /dev/null @@ -1,18 +0,0 @@ -/* - * - * Exercise 4-14. Define a macro swap(t,x,y) that interchanges two arguments of type t. - * - * Author: Kun Deng - */ - - -// Macro definition -// #define swap(t, x, y) - - -int main() -{ - - - return 0; -}