-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathex3_2.c
60 lines (52 loc) · 795 Bytes
/
ex3_2.c
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#include <stdio.h>
void escape(char s[], char t[])
{
int i = 0;
int j = 0;
while (t[i] != '\0') {
switch (t[i]) {
case '\n': case '\t':
s[j++] = '\\';
s[j++] = (t[i] == '\n') ? 'n' : 't';
break;
default:
s[j++] = t[i];
break;
}
i++;
}
s[j] = '\0';
}
void rev_escape(char s[], char t[])
{
int i = 0;
int j = 0;
while (s[i] != '\0') {
switch (s[i]) {
case '\\':
i++;
switch (s[i+1]) {
case 'n':
t[j++] = '\n';
break;
case 't':
t[j++] = '\t';
break;
}
break;
default:
t[j++] = s[i];
}
i++;
}
t[i] = '\0';
}
int main() {
char t[10] = "adele\n";
char s[10];
escape(s, t);
printf("%s\n", s);
rev_escape(s, t);
printf("%s", t);
return 0;
}