include stdio include stdlib include string include conio void shell c

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <conio.h>
void shell(char **p, int n) {
register int i, j, g, k;
int a[5]={9, 5, 3, 2, 1};
char strl[255];
for (k=0; k<5; k++) {
g=a[k];
for (i=g; i<=n; ++i) {
strcpy(strl, p[i]);
for (j=i-g; ((strlen(strl))<strlen(*(p+j))) && (j>=0); j=j-g)
strcpy(p[j+g], p[j]);
strcpy(p[j+g], strl);
}
}
}
int main() {
char str[255];
int n, i;
char **p;
printf("vvedite koli4estvo strok>> ");
do {
scanf("%d", &n);
} while (n<=0);
p=(char**)calloc(n, sizeof(char*));
if(!p){
printf("nehvatka pam9ti");
exit(1);
}
for(i=0; i<=n; i++) {
gets(str);
p[i]=(char*)calloc(strlen(str), sizeof(char));
strcpy(p[i], str);
}
shell(p, n);
for(i=0; i<=n; i++){
printf ("%s\n", p[i]);
}
system("pause");
return 0;
}