#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define W_SIZE 15
int main()
{
char (*pl)[W_SIZE];
int words;
int i=0;
int k;
printf("How many words do you wish to enter:");
scanf("%d",&words);
printf("Enter %d words now.\n",words);
pl=(char (*)[W_SIZE])malloc(words*W_SIZE*sizeof(char));
while(i<words&&scanf("%s",pl[i])==1)
i++;
printf("Here are your words:\n");
for(k=0;k<words;k++)
puts(pl[k]);
free(pl);
return 0;
}
C Primer plus 6th 第12章9题参考答案
最新推荐文章于 2025-12-02 15:10:47 发布
本文介绍了一个使用C语言进行动态内存分配的例子,通过数组指针接收用户输入的多个字符串,并将其打印出来,展示了如何使用malloc和free进行内存管理。
341

被折叠的 条评论
为什么被折叠?



