2 5dc21454 2023-07-14 jrmu * 3-2. Write a function escape(s,t) that converts characters like newline
3 5dc21454 2023-07-14 jrmu * and tab into visible escape sequences like \n and \t as it copies the
4 5dc21454 2023-07-14 jrmu * string t to s. Use a switch. Write a function for the other direction as
5 5dc21454 2023-07-14 jrmu * well, converting escape sequences into the real characters.
8 5dc21454 2023-07-14 jrmu #include <stdio.h>
10 5dc21454 2023-07-14 jrmu void escape(char s[], char t[]);
14 5dc21454 2023-07-14 jrmu char str[400];
15 5dc21454 2023-07-14 jrmu escape (str, "This\t\t\t is a test\n to see\n\t\t if escaping works");
16 5dc21454 2023-07-14 jrmu printf("%s\n", str);
19 5dc21454 2023-07-14 jrmu void escape(char s[], char t[]) {
21 5dc21454 2023-07-14 jrmu for (i = 0, j = 0; t[j] != '\0'; ++i, ++j) {
22 5dc21454 2023-07-14 jrmu switch (t[j]) {
24 5dc21454 2023-07-14 jrmu s[i++] = '\\';
28 5dc21454 2023-07-14 jrmu s[i++] = '\\';
32 5dc21454 2023-07-14 jrmu s[i] = t[j];
36 5dc21454 2023-07-14 jrmu s[i] = t[j];