You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
/* Prepends t into s. Assumes s has enough space allocated
** for the combined string.
*/
void prepend(char* s, const char* t)
{
size_t len = strlen(t);
size_t i;
memmove(s + len, s, strlen(s) + 1);
for (i = 0; i < len; ++i)
{
s[i] = t[i];
}
}
问题1:添加字符到字符数组头部
问题描述:因为C语言中不能使用
+
来拼接字符串,那如何向字符数组开头添加字符?解决方案:使用
memmove
方式,将字符数组中已有数据往后一个位置。memmove
的相关介绍 C library function - memmove()。如果需要添加字符串到头部,可以封装一个函数:参考:Prepending to a string
The text was updated successfully, but these errors were encountered: