在 C 语言中,可以使用动态内存分配函数 malloc()
来为存储中文字符串的数组分配内存,示例代码如下:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main() {
char *str;
int len;
printf("请输入字符串长度: ");
scanf("%d", &len);
str = (char *)malloc((len + 1) * sizeof(char)); // 分配内存
printf("请输入字符串: ");