要求:
输入多个字符串,个数不定,最后以#字符串结束
代码:
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define N 255
int main()
{
char **str, temp[N];
int count = 1;
int i;
str = (char**)malloc(sizeof(char*) * count);
while(gets(temp), strcmp(temp, "#") != 0)
{
str = (char**)realloc(str, sizeof(char*) * count);
str[count-1] = (char*)malloc(sizeof(char) * N);
strcpy(str[count-1], temp);
count++;
}
//Output
for(i = 0; i < count-1; i++)
{
puts(str[i]);
}
return 0;
}