c - 接受用户输入并将其添加到数组中的函数

标签 c arrays

我有一个作业问题要完成这个方法。我真的不知道该怎么办。给出这个伪代码有人可以帮我写这个方法吗?

/*
    make a new array of the old size plus the new size
    copy from the old to the new
    add the new characters
    don't forget to clean up the old array (free it)
    before you leave this function
*/

char * add(char * array, int num)
{
    return array;

}

最佳答案

由于这是 C,请查看 realloc - 但您还需要一个旧大小的参数(或者可能使用 strlen)

关于c - 接受用户输入并将其添加到数组中的函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9706828/

相关文章:

java - 如何计算数组列包含元素的行

java - 如何以相反的顺序获取 char 数组?

c - 如何获取变量 ASCII 值并将其用于求和

c - 使用函数指针的正确风格是什么?

c - 如何获取 Windows session 名称?

c - 在 C 中返回一个 void 指针作为函数参数

c - 后台进程在终止前捕获进程 ID

ruby - 为什么在二维数组中赋值会有不同的结果?

java - 将整数放入数组中的链表中

c++ - C++中指向数组的指针的奇怪行为