6-29 Esc Chars (20分)

6-29 Esc Chars (20分)
Esc characters are represented as \x in C string, such as \n and \t.
Function prt_esc_chars() gets a string which may contains esc characters, and prints the string into the standard ouput with all esc characters been replaced by a \x format combination.
For example, using printf("%s"…, a string with a \n between the words will be printed as:
Hello
World
But the same string will be printed by prt_esc_chars() as:
Hello\nWorld
Your function should be able to recognize esc characters below:
\n
\r
\t
\b
And all other characters below 0x20 should be printed as:
\hh
where hh is the hexadecimal of the value, all letters in capital. For a value below 0x10, a leading 0 is needed to keep two positions.
And as a C string, 0x00 will not be part of the string but the terminator.
Be aware, printf() is forbidden in the function.
函数接口定义:
int prt_esc_char(const char *s);
s is the string to be printed. The function returns the number of characters printed. An esc character is counted as two or three according to the characters it uses.
裁判测试程序样例:
#include <stdio.h>
int prt_esc_char(const char *s);
int main()
{
char line = NULL;
size_t linecap = 0;
getline(&line, &linecap, stdin);
int len = prt_esc_char(line);
printf("%d\n", len);
}
/
请在这里填写答案 */
输入样例:
hello world
There is a tab between hello and world.
输出样例:
hello\tworld\n14


                
  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值