在程序开始时,我需要为未知数量的字符串(大小未知)动态分配内存,以便以后使用。要获得用户的字符串数,我需要:
int main(int argc, char *argv[]){
int number = atoi(argv[1]);
Run Code Online (Sandbox Code Playgroud)
到目前为止,一切都很好。现在,“ number”保存着用户在命令行上输入的用于执行代码的数字。现在是我不太了解的部分。现在,我需要动态存储字符串的长度以及字符串的内容。例如,我希望程序运行如下:
Enter the length of string 1: 5
Please enter string 1: hello
Enter the length of string 2: ...
Run Code Online (Sandbox Code Playgroud)
为此,我认识到必须创建一个字符串数组。但是,我不太了解指针的概念,而没有。我想要的可能是如何简化此过程?