| 1 |
#include <stdio.h> |
| 2 |
#include <stdlib.h> |
| 3 |
#include <string.h> |
| 4 |
|
| 5 |
int main(int argc, char *argv[]) |
| 6 |
{ |
| 7 |
int j, len, n = 500000; |
| 8 |
char *s = NULL, *p; |
| 9 |
|
| 10 |
if (argc > 1) |
| 11 |
n = atoi(argv[1]); |
| 12 |
|
| 13 |
for (j = 0; j < 10; j++) { |
| 14 |
free(s); |
| 15 |
s = strdup("abcdef"); |
| 16 |
while ((len = strlen(s)) <= n) { |
| 17 |
p = (char *) malloc(2 * len + 10); |
| 18 |
sprintf(p, "123%s456%s789", s, s); |
| 19 |
free(s); |
| 20 |
s = p; |
| 21 |
len = strlen(s); |
| 22 |
p = (char *) malloc(len + 2); |
| 23 |
strcpy(p, s + len/2); |
| 24 |
strncat(p + len/2, s, len/2+1); |
| 25 |
free(s); |
| 26 |
s = p; |
| 27 |
} |
| 28 |
} |
| 29 |
printf("%d\n", strlen(s)); |
| 30 |
return 0; |
| 31 |
} |