2014年05月15日

practice 3-2:Write a function escape(s,t),copy string t to string s,and display some invisable charactor like '\n' '\t' and so on,make them visable,with switch sentence grammer.Then write another function which has a opposite affect,that is to turn those charactor to be invisable.

#include
#define MAXLINE 100

void escape(char s[],char t[])
{
 int i,j=0;
 for(i=0;t[i]!='\0';++i)
 {
  switch(t[i])
  {
  case '\t':
   s[j++]='\\';
   s[j]='t';
   ++j;
   break;
  case '\n':
   s[j++]='\\';
   s[j]='n';
   ++j;
   break;
  default:
   s[j]=t[i];
   ++j;
   break;
  }
 }
 s[j]='\0';


}
void  inverse(char t[],char s[])
{
 int i,j=0;

 for(i=0;s[i]!='\0';++i)
 {
  switch(s[i])
  {
   case '\\':
    {
    switch(s[i+1])
    {
     case 't':
      t[j++]='\t';
      ++i;
      break;
     case 'b':
      t[j++]='\b';
      ++i;
      break;
     case 'n':
      t[j++]='\n';
      ++i;
      break;
     default:
      break;
    }
    break;
    }
   default:
    t[j++]=s[i];
    
    break;
  }
 }
 t[j]='\0';

 
}
main()
{
 char s1[MAXLINE]="\aHello,\n\tWorld! Mistakee\b was \"Extra 'e'\"!\n";
 char s2[MAXLINE];
 
 printf("the original string:\n%s\n",s1);

 escape(s2,s1);
 printf("escape string:\n%s\n",s2);
 
 inverse(s1,s2);
 printf("inverse string:\n%s\n",s1);

 return 0; 
}

 

Conclusion:To find out what it is wrong within procesures is the most tough job for me ,and it takes lots of my time .A long time ago,I will choose to give up or give in to it.But now, I reallize what can make me feel a little of successful is not the right answers do I give but the difficult in the process do I conquer.More questions,more exciting!So,let's move on,and welcome troubles.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值