Exercise 3-2. Write a function escape(s,t) that converts characters like newline and tab into visible escape sequences like \n and \t as it copies the string t to s. Use a switch. Write a function for the other direction as well, converting escape sequences into the real characters.
/* Exercise 3-2. Write a function escape(s,t) that converts characters like newline and tab into visible escape sequences like \n and \t as it copies the string t to s. Use a switch. Write a function for the other direction as well, converting escape sequences into the real characters. */#include<stdio.h>#include<string.h>#define LIMIT 200voidescape(chars[],chart[]);voidescape_reverse(chars[],chart[]);intmain(){chars[LIMIT];chart[LIMIT/2]="a bc d t";escape(s,t);/* 's' is modified in-place, by using 't' as input*/printf("converting escape characters to visible escape sequences.\n");printf("---------------------------------------------------------\n");printf("input string t = '%s'\noutput string s = '%s'\n\n",t,s);escape_reverse(s,t);/* 't' is modified in-place by using modified 's' as input*/printf("converting visible escape sequences to real characters.\n");printf("---------------------------------------------------------\n");printf("input string s = '%s'\noutput string t = '%s'\n",s,t);return0;}voidescape(chars[],chart[]){inti,j,c;for(i=0,j=0;i<((int)strlen(t));i++,j++){c=t[i];switch(c){case'\t':s[j]='\\';j++;s[j]='t';break;case'\n':s[j]='\\';j++;s[j]='\n';break;default:s[j]=t[i];break;}}s[j]='\0';}voidescape_reverse(chars[],chart[]){inti,j,c;for(i=0,j=0;i<((int)strlen(s));i++,j++){c=s[i];switch(c){case'\\':t[j]=((s[++i]=='t')?'\t':((s[++i]=='n')?'\n':'\\'));break;default:t[j]=s[i];break;}}t[j]='\0';}