我打开一个文件,获取它的内容,寻找一个正则表达式模式的匹配项,然后将匹配项一一打印出来。有些匹配包含八进制符号,例如。 \012
换行。
当我简单地应用printf("%s\n", match);
时,它被打印为\012
。有没有办法打印出相应的ASCII字符(在这种情况下为换行符)?
答案 0 :(得分:1)
If match
is a string, you can use the function strtol
in <stdlib.h>
to convert it to an int
by specifying base 8:
int num = strtol(match + 1, NULL, 8);
Note that I incremented the pointer to match
by 1 since it begins with a "\\"
which strtol
will stop on.