posts - 26,comments - 0,views - 2155

Archlinux

GCC 13.1.1  20230429

2023-07-30 12:57:46 星期日

 


点击查看代码
#include<stdio.h>


void escape( char s[], char t[] )
{
    int i, j;

    i = j = 0;

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

    s[j] = '\0';
}

void unescape( char s[], char t[] )
{
    int x, y;

    x = y = 0;

    while( t[x] != '\0' )
    {
        if( t[x] == '\\' ){
            switch( t[++x] )
            {
                case 'n': s[y] = '\n'; break;
                case 't': s[y] = '\t'; break;
            }
        }
        else
        {
            s[y] = t[x];
        }

        x++;
        y++;
        s[y] = '\0';
    }
}

int main()
{
    char arr[]= "xdq\tzs\n";
    char tmp[100];
    
    escape( tmp, arr );

    printf("%s\n", tmp);

    unescape( arr, tmp );

    printf("%s\n", arr );


    return 0;
}


 


运行截图:

image

输出正确。

 


小白刚学习C语言,代码质量不高,欢迎评论。

posted on   语巫  阅读(164)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 25岁的心里话
· 闲置电脑爆改个人服务器(超详细) #公网映射 #Vmware虚拟网络编辑器
· 零经验选手,Compose 一天开发一款小游戏!
· 通过 API 将Deepseek响应流式内容输出到前端
· AI Agent开发,如何调用三方的API Function,是通过提示词来发起调用的吗
< 2025年3月 >
23 24 25 26 27 28 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 1 2 3 4 5

点击右上角即可分享
微信分享提示