fork download
  1.  
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. #include <malloc.h>
  5.  
  6. typedef struct{
  7. int **array;
  8. int **pointers;
  9. int stacks_number;
  10. int size;
  11. }Stacks_array;
  12.  
  13. void init_array(Stacks_array *array){
  14. // Ввод числа стеков
  15. int N;
  16. printf("\nType number of stacks: ");
  17. if ((scanf("%d", &N) == 0) || (N < 3)){
  18. printf("\nError.*\n ");
  19. exit(-1);
  20. }
  21. array->stacks_number = N;
  22. // Ввод начальных размеров стеков
  23. (*array->pointers) = (int**)malloc(sizeof(int*));
  24. array->pointers = (int*)malloc(sizeof(int)*N);
  25. array->pointers[0] = 0;
  26. for (int i = 0; i < N; i++) {
  27. int tmp;
  28. printf("\nType size of stack number %d: ", i);
  29. if ((scanf("%d", &tmp) == 0) || ( tmp < 2)) {
  30. printf("\nError. Try again.\n ");
  31. i--;
  32. continue;
  33. }
  34. array->pointers[i + 1] = array->pointers[i] + tmp;
  35. if (i != N - 1)
  36. array->size += tmp;
  37. }
  38. // Инициализация массива
  39. array->array = (int*) malloc(sizeof(int)*array->size);
  40. }
  41.  
  42. int main() {
  43. Stacks_array array;
  44. init_array(&array);
  45. return 0;
  46. }
  47. // Инициализация массива
  48. array->array = (int*) malloc(sizeof(int)*array->size);
  49. }
  50.  
  51. int main() {
  52. Stacks_array array;
  53. init_array(&array);
  54. return 0;
  55. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.c: In function 'init_array':
prog.c:23:24: warning: assignment from incompatible pointer type [-Wincompatible-pointer-types]
     (*array->pointers) = (int**)malloc(sizeof(int*));
                        ^
prog.c:24:21: warning: assignment from incompatible pointer type [-Wincompatible-pointer-types]
     array->pointers = (int*)malloc(sizeof(int)*N);
                     ^
prog.c:39:18: warning: assignment from incompatible pointer type [-Wincompatible-pointer-types]
     array->array = (int*) malloc(sizeof(int)*array->size);
                  ^
prog.c: At top level:
prog.c:48:10: error: expected '=', ',', ';', 'asm' or '__attribute__' before '->' token
     array->array = (int*) malloc(sizeof(int)*array->size);
          ^
prog.c:49:1: error: expected identifier or '(' before '}' token
 }
 ^
prog.c:51:5: error: redefinition of 'main'
 int main() {
     ^
prog.c:42:5: note: previous definition of 'main' was here
 int main() {
     ^
stdout
Standard output is empty