当前位置: 动力学知识库 > 问答 > 编程问答 >

c - Converting char arrays with literal escape sequences into char

问题描述:

I have a C tokenizer library I'm using for a personal project.

It returns escaped characters as a char array of literals. So for example the string "\n" gets returned as this char array:

[][n]

Instead of this (desired) array:

[\n]

Is there an easy way in C to convert the first char array into the second char array without manual parsing?

Here is code example of what I'm after:

char test[2];

test[0] = '\\';

test[1] = 'n';

char c = someFunction(test)

printf("A %c B", c);

Desired Output:

A

B

Is there a way to do this using any obscure tricks or do I need to roll my own function?

Thanks!

分享给朋友:
您可能感兴趣的文章:
随机阅读: