我想保存更多的字符,ch[500]
然后它已经存在了。我不想丢失我以前保存在那里的字符。
可以这样工作的东西:
ch = ch + ’nextch’;
您可以使用strcat()
orstrncat()
来连接两个字符串。
例如
char ch[100];
strcpy(ch,"hello");
strcat(ch," world");
如果你只想附加一个字符
char str[100];
strcpy(str,"hello");
char ch='a';
char buf[2];
sprintf(buf,"%c",ch);
strncat(str,sizeof str, buf);
或者
size_t length= strlen(str);
str[strlen(str)]=ch;
str[length+1]='\0';