获取用户输入并将其添加到数组的函数

我有一个功课问题来完成这个方法。 我真的不知道该怎么做。 鉴于这个psuedocode有人可以帮我写这个方法吗?

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

这是一个伪代码:

 char * add(char * old_array, int old_size, char *additions, int new_size) { malloc new_size bytes and assign to new_array memcpy old_size bytes from old_array into the new_array add additions into new_array starting from (new_array+old_size) free the old_araray return new_array; }