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
完成了第一个函数 把不可见的tab和换行转换成\t和\n,可以从键盘输入或者文件输入
#include <stdio.h>
#define MAX 10000
/* author: xiaowh00 */
/* date: 2012-6-19 */
/*
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
*/
void escape(char s[],char t[])
{
int i,j;
for(i=0,j=0;t!='\0';i++)
{
switch(t)
{
case '\n': s[j++]='\\';s[j++]='n';break;
case '\t': s[j++]='\\';s[j++]='t';break;
default: s[j++]=t;break;
}
}
}作者: xiaowh00 时间: 2012-06-19 17:01
第二个函数,将显示的\n和\t转换成实际的换行和tab
#include <stdio.h>
#define MAX 10000
/*
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
*/
/* author: xiaowh00 */
/* date: 2012-6-19 */