strcat 将一个字符连接到一个字符串上? [英] strcat concat a char onto a string?
本文介绍了strcat 将一个字符连接到一个字符串上?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
使用 GDB,我在尝试此操作时发现出现分段错误:
Using GDB, I find I get a segmentation fault when I attempt this operation:
strcat(string,¤tChar);
假设字符串被初始化为
char * string = "";
而 currentChar 是
and currentChar is
char currentChar = 'B';
为什么会导致分段错误?
Why does this result in a segmentation fault?
如果 strcat 不能用于此,我还能如何将 char 连接到字符串上?
If strcat can't be used for this, how else can I concat a char onto a string?
推荐答案
因为 ¤tChar
不是字符串,所以它没有以