字符追加至字符串使用C? [英] Append Char To String in C?

查看:524
本文介绍了字符追加至字符串使用C?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何将单个字符追加到在C字符串?

 的char *海峡=blablabla;
焦C ='H';
str_append(STR,C); / * * blablablaH /


解决方案

 的char *海峡=blablabla;

您不应该在所有的修改此字符串。它位于实现定义的只读区域。修改它导致的未定义行为即可。

您需要一个字符数组不是字符串常量。

好阅读:结果
<一href=\"http://stackoverflow.com/questions/9460260/what-is-the-difference-between-char-a-string-and-char-p-string/9631091#9631091\">What为char之间的[] =串的区别;和char * p =串;

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 */

解决方案

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";

这篇关于字符追加至字符串使用C?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆