|
发表于 2003-3-28 10:30:39
|
显示全部楼层
[code:1]
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int
main(void)
{
char **x = NULL;
char s[1024], *t;
int xn = 10, n = 0, i;
printf("Please enter a string: ");
fgets(s, 1024, stdin);
s[strlen(s) - 1] = '\0';
x = (char **)realloc(x, xn * sizeof(*x));
t = strtok(s, " ");
while(t){
if(n >= xn){
xn += 10;
x = (char **)realloc(x, xn * sizeof(*x));
}
x[n++] = t;
t = strtok(NULL, " ");
}
printf("\nEnter string:\n");
for(i = 0; i < n; i++)
printf(" %s\n", x[i]);
free(x);
exit(0);
}
[/code:1] |
|