Append Char To String in C?

前端 未结 9 1122
滥情空心
滥情空心 2020-11-27 16:17

How do I append a single char to a string in C?

i.e

char* str = \"blablabla\";
char c = \'H\';
str_append(str,c); /* blablablaH */
9条回答
  •  长情又很酷
    2020-11-27 16:45

    char* str = "blablabla";     
    

    You should not modify this string at all. It resides in implementation defined read only region. Modifying it causes Undefined Behavior.

    You need a char array not a string literal.

    Good Read:
    What is the difference between char a[] = "string"; and char *p = "string";

提交回复
热议问题