-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathswap.c
More file actions
34 lines (31 loc) · 704 Bytes
/
Copy pathswap.c
File metadata and controls
34 lines (31 loc) · 704 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#include <stdio.h>
void swap_int(int *x, int *y)
{
int tmp = *y;
*y = *x;
*x = tmp;
}
void reverse_string(char *str)
{
char *last_char;
for(last_char = str; *last_char != '\0'; last_char++)
;
last_char--;
while(str < last_char)
{
char tmp;
tmp = *str;
*str++ = *last_char;
*last_char-- = tmp;
}
}
int main(int argc, char *argv[])
{
int i = 1, j = 2;
swap_int(&i, &j);
printf("i = %d, j = %d\n", i, j);
char *str = "string";
reverse_string(str);
printf("Reversed string: %s", str);
return 0;
}