6-30 Read Esc Chars (30分)(函数)

该博客介绍了一个C语言函数,用于读取包含转义字符(如 , , , )的字符串,并将其转换为实际的转义字符。例如,将' '转换为制表符。函数`read_esc_char`从标准输入读取一行,返回转换后的字符串长度。若输入超出缓冲区大小,仅处理安全存储的部分。文章还提到了处理其他控制字符和越界检查的情况。" 117741014,10549002,HTML实现div横向滚动布局,"['前端开发', 'CSS', 'HTML', '布局']
摘要由CSDN通过智能技术生成

6-30 Read Esc Chars (30分)(函数)

Esc characters are represented as \x in C string, such as \n and \t.
Function read_esc_chars() reads a line that may contains esc character representations from the standard input and parses all those esc character representations into esc characters.
For example, a string:
This is \t a test.
will be converted as:
This is a test.
There is a tab between is and a.
Your function should be able to recognize esc characters below: \n
\r
\t
\b
And all other characters below 0x20 will be presented 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.
函数接口定义:
int read_esc_char(char *line, int len);
line is the place that can hold the string read from user’s input.
len is the size of line.
The function reads a whole line from the standard input and returns number of characters in the converted string. If the inputed line is longer than the place, only the characters that can be safely placed in the place can be read in.
裁判测试程序样例:
#include <stdio.h>
int read_esc_char(char line, int len);
static const LINE_LEN = 80;
int main()
{
char line[LINE_LEN];
printf("%d\n", read_esc_char(line, LINE_LEN));
printf("%s\n", line);
}
/
请在这里填写答案 */
输入样例:
hello\tworld
输出样例:
11
hello world
There is a tab between hello and world.

int read_esc_char(char *line, int len){
   
    
  • 6
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值