Finished exercise 04-14
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -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 <stdio.h>
|
||||
|
||||
// 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;
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
Reference in New Issue
Block a user