gpt4 book ai didi

c - 在C中动态分配未指定大小的数组

转载 作者:行者123 更新时间:2023-11-30 18:14:16 26 4
gpt4 key购买 nike

我想在 c 中输入一个输入,但不知道数组大小。请建议我如何做到这一点..

hello this is
a sample
string to test.

最佳答案

malloc 是一种方法:

char* const string = (char*)malloc(   NCharacters   ); // allocate it
...use string...
free(string); // free it

其中 NCharacters 是该数组中所需的字符数。

关于c - 在C中动态分配未指定大小的数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16603312/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com