diff --git a/Lesson/14.03/l2.c b/Lesson/14.03/l2.c index 6405018..933a428 100644 --- a/Lesson/14.03/l2.c +++ b/Lesson/14.03/l2.c @@ -2,19 +2,16 @@ #include #include #include - #define N 5 - struct st1{ int i; char s[128]; }; - void st_rand(struct st1 temp[], int n){ int k; int j; - srand(time(NULL)); + for(k=0; ki = rand()%100; for(j=0;j<127;j++){ @@ -23,7 +20,6 @@ void st_rand(struct st1 temp[], int n){ (temp+k)->s[127]='\0'; } } - /*void swap(struct st1 temp[], int c, int d, int n){ Дописать функцию! } @@ -34,12 +30,17 @@ void st_print(struct st1 temp[], int n){ printf("%d->[%2d][%s]\n", k, temp[k].i, (temp+k)->s); } } - int main(int argc, char *argv[]){ - struct st1 q[N]; - - st_rand(q,N); - st_print(q,N); + struct st1 *pq=NULL; + srand(time(NULL)); + if((pq=malloc(N*sizeof(struct st1))) == NULL){ + printf("malloc: NULL\n"); + exit(2); + } + st_rand(pq,N); + st_print(pq,N); + free(pq); + pq = NULL; return 0; } \ No newline at end of file