fork download
  1. typedef int valuetype;
  2.  
  3. typedef struct {
  4. size_t tos;
  5. size_t length;
  6. valuetype *values;
  7. } stack;
  8.  
  9. typedef struct {
  10. stack *stacks;
  11. size_t length;
  12. } stacklist;
  13.  
  14. static void fatal(const char *message) {
  15. fprintf(stderr, "pizdariki: %s\n", message);
  16. exit(EXIT_FAILURE);
  17. }
  18.  
  19. static valuetype stack_get(stack *stack) {
  20. if (stack->tos == 0) {
  21. fatal("empty stack");
  22. }
  23.  
  24. return stack->values[stack->tos - 1];
  25. }
  26.  
  27. static valuetype stack_pop(stack *stack) {
  28. if (stack->tos == 0) {
  29. fatal("stack underflow");
  30. }
  31.  
  32. return stack->values[--stack->tos];
  33. }
  34.  
  35. static void stack_push(stack *stack, valuetype value) {
  36. if (stack->tos == stack->length) {
  37. fatal("stack overflow");
  38. }
  39.  
  40. stack->values[stack->tos++] = value;
  41. }
  42.  
  43.  
  44. static void stack_init(stack *stack, size_t length) {
  45. stack->tos = 0;
  46. stack->length = length;
  47. stack->values = malloc(sizeof(*stack->values) * stack->length);
  48.  
  49. if (!stack->values) {
  50. fatal("no memory");
  51. }
  52. }
  53.  
  54. static void stacklist_init(stacklist *list) {
  55. size_t list_length;
  56. printf("Type number of stacks: ");
  57. if (!scanf("%zu", &list_length)) {
  58. fatal("wrong input");
  59. }
  60.  
  61. list->length = list_length;
  62. list->stacks = malloc(sizeof(*list->stacks) * list_length);
  63. if (!list->stacks) {
  64. fatal("no memory");
  65. }
  66.  
  67. for (size_t i = 0; i < list_length; i++) {
  68. size_t stack_length;
  69. printf("Type length of the stack %zu: ", i);
  70. if (!scanf("%zu", &stack_length)) {
  71. fatal("wrong input");
  72. }
  73. stack_init(&list->stacks[i], stack_length);
  74. }
  75. }
  76.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.c:4:5: error: unknown type name 'size_t'
     size_t tos;
     ^
prog.c:5:5: error: unknown type name 'size_t'
     size_t length;
     ^
prog.c:11:5: error: unknown type name 'size_t'
     size_t length;
     ^
prog.c: In function 'fatal':
prog.c:15:5: error: implicit declaration of function 'fprintf' [-Werror=implicit-function-declaration]
     fprintf(stderr, "pizdariki: %s\n", message);
     ^
prog.c:15:5: error: incompatible implicit declaration of built-in function 'fprintf' [-Werror]
prog.c:15:5: note: include '<stdio.h>' or provide a declaration of 'fprintf'
prog.c:15:13: error: 'stderr' undeclared (first use in this function)
     fprintf(stderr, "pizdariki: %s\n", message);
             ^
prog.c:15:13: note: each undeclared identifier is reported only once for each function it appears in
prog.c:16:5: error: implicit declaration of function 'exit' [-Werror=implicit-function-declaration]
     exit(EXIT_FAILURE);
     ^
prog.c:16:5: error: incompatible implicit declaration of built-in function 'exit' [-Werror]
prog.c:16:5: note: include '<stdlib.h>' or provide a declaration of 'exit'
prog.c:16:10: error: 'EXIT_FAILURE' undeclared (first use in this function)
     exit(EXIT_FAILURE);
          ^
prog.c: At top level:
prog.c:44:38: error: unknown type name 'size_t'
 static void stack_init(stack *stack, size_t length) {
                                      ^
prog.c: In function 'stacklist_init':
prog.c:55:5: error: unknown type name 'size_t'
     size_t list_length;
     ^
prog.c:56:5: error: implicit declaration of function 'printf' [-Werror=implicit-function-declaration]
     printf("Type number of stacks: ");
     ^
prog.c:56:5: error: incompatible implicit declaration of built-in function 'printf' [-Werror]
prog.c:56:5: note: include '<stdio.h>' or provide a declaration of 'printf'
prog.c:57:10: error: implicit declaration of function 'scanf' [-Werror=implicit-function-declaration]
     if (!scanf("%zu", &list_length)) {
          ^
prog.c:57:10: error: incompatible implicit declaration of built-in function 'scanf' [-Werror]
prog.c:57:10: note: include '<stdio.h>' or provide a declaration of 'scanf'
prog.c:57:16: error: format '%zu' expects argument of type 'size_t *', but argument 2 has type 'int *' [-Werror=format=]
     if (!scanf("%zu", &list_length)) {
                ^
prog.c:62:20: error: implicit declaration of function 'malloc' [-Werror=implicit-function-declaration]
     list->stacks = malloc(sizeof(*list->stacks) * list_length);
                    ^
prog.c:62:20: error: incompatible implicit declaration of built-in function 'malloc' [-Werror]
prog.c:62:20: note: include '<stdlib.h>' or provide a declaration of 'malloc'
prog.c:67:10: error: unknown type name 'size_t'
     for (size_t i = 0; i < list_length; i++) {
          ^
prog.c:68:9: error: unknown type name 'size_t'
         size_t stack_length;
         ^
prog.c:70:14: error: incompatible implicit declaration of built-in function 'scanf' [-Werror]
         if (!scanf("%zu", &stack_length)) {
              ^
prog.c:70:14: note: include '<stdio.h>' or provide a declaration of 'scanf'
prog.c:70:20: error: format '%zu' expects argument of type 'size_t *', but argument 2 has type 'int *' [-Werror=format=]
         if (!scanf("%zu", &stack_length)) {
                    ^
prog.c:73:9: error: implicit declaration of function 'stack_init' [-Werror=implicit-function-declaration]
         stack_init(&list->stacks[i], stack_length);
         ^
prog.c: At top level:
prog.c:19:18: error: 'stack_get' defined but not used [-Werror=unused-function]
 static valuetype stack_get(stack *stack) {
                  ^
prog.c:27:18: error: 'stack_pop' defined but not used [-Werror=unused-function]
 static valuetype stack_pop(stack *stack) {
                  ^
prog.c:35:13: error: 'stack_push' defined but not used [-Werror=unused-function]
 static void stack_push(stack *stack, valuetype value) {
             ^
prog.c:54:13: error: 'stacklist_init' defined but not used [-Werror=unused-function]
 static void stacklist_init(stacklist *list) {
             ^
cc1: all warnings being treated as errors
stdout
Standard output is empty