How to Initialize char array from a string

后端 未结 11 2023
时光说笑
时光说笑 2020-12-14 09:19

I want to do the following

char a[] = { \'A\', \'B\', \'C\', \'D\'};

But I do not want to write these characters separately. I want somethi

11条回答
  •  难免孤独
    2020-12-14 09:47

    Weird error.

    Can you test this?

    const char* const S = "ABCD";
    char t[] = { S[0], S[1], S[2], S[3] };
    char u[] = { S[3], S[2], S[1], S[0] };
    

提交回复
热议问题