fork(2) download
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. typedef struct {
  5. int size; //size of array
  6. int *array;
  7. } mystruct;
  8.  
  9. mystruct * create_mystruct(int size) {
  10. mystruct * st = (mystruct*) malloc(sizeof(mystruct));
  11. st->size = size;
  12. st->array = (int *) malloc(sizeof(int) * size);
  13. return st;
  14. }
  15.  
  16. int main(void) {
  17. int size, i, x;
  18. scanf("%d", &size);
  19. mystruct * st = create_mystruct(size);
  20. for(i = 0; i < size; i++) {
  21. scanf("%d", &x);
  22. st->array[i] = x;
  23. }
  24. for(i = 0; i < size; i++) {
  25. printf("%d\n", st->array[i]);
  26. }
  27. free(st->array);
  28. free(st);
  29. return 0;
  30. }
  31.  
Success #stdin #stdout 0s 2248KB
stdin
5
12 48 3 -1 8
stdout
12
48
3
-1
8