fork download
  1. #include <stdio.h>
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. #include <string.h>
  5. //#include "list.h"
  6. int main(int argc, char* argv[]) {
  7. list_t* list = list_create();
  8. for(int i = 0; i < 5; i++)
  9. list_append(list, i);
  10. for(int i = -1; i > -5; i--)
  11. list_prepend(list, i);
  12. printf("Array: ");
  13. list_print(list);
  14. int index = 2;
  15. element_t* el_1 = list_index(list, index);
  16. if(el_1 == NULL) {
  17. printf("FAIL index %d is not in array\n", index);
  18. return 1;
  19. }
  20. printf("value at index %d is %d\n", index, el_1->val);
  21. printf("Next Task\n");
  22. printf("Testing tasks 2 to 6\n");
  23. if(el_1->val != -2)
  24. return 1;
  25.  
  26.  
  27.  
  28.  
  29. //Task 2
  30. printf("Testing Task 2\n");
  31. element_t* el_2 = element_create(9);
  32. if(el_2->val != 9) {
  33. printf("el_2->val is supposed to be 9 but isn't\n");
  34. return 1;
  35. }
  36.  
  37. if(el_2 == NULL) {
  38. printf("MEM ALLOC FAIL");
  39. return 1;
  40. }
  41.  
  42. element_t* el_3 = element_create(99);
  43. list_t* list_2 = list_create();
  44. for(int i = 0; i < 5; i++)
  45. list_append( list_2, i);
  46. for(int i = -1; i > -5; i--)
  47. list_prepend(list_2, i);
  48. if (list->tail->val != 4){
  49. printf("TAIL ERROR\n");
  50. return 1;
  51. }
  52.  
  53. el_3->next = list_index(list_2, 3);
  54. free(el_3->next);
  55. el_3 = element_create(100);
  56. if(el_3->next != NULL){
  57. printf("el_3->next is supposed to be NULL but isn't\n");
  58. return 1;
  59. }
  60. printf("Task 2 Passed\n");
  61.  
  62.  
  63.  
  64.  
  65. //Task 3
  66. printf("Testing Task 3\n");
  67. list_t* list_3 = list_create();
  68. element_t* el_4 = list_index(list_3, 5);
  69. if(el_4 != NULL) {
  70. printf("el_4 is supposed to be NULL but isn't\n");
  71. return 1;
  72. }
  73. printf("Task 3 Passed\n");
  74.  
  75.  
  76.  
  77.  
  78. //Task 4
  79. printf("Testing Task 4\n");
  80. list_t* list_4 = list_create();
  81. list_prepend(list_4, 800);
  82. if(list_4->tail->val != 800) {
  83. printf("list_4->tail is supposed to be 800 but isn't\n");
  84. return 1;
  85. }
  86. printf("Task 4 Passed\n");
  87.  
  88.  
  89.  
  90.  
  91. //Task 5
  92. printf("testing list_create(t5)...\n");
  93. list_t* list_5 = list_create();
  94. list_5->head = element_create(666);
  95. list_5->head->next = element_create(333);
  96. list_5->tail = list_5->head->next;
  97. free(list_5);
  98. list_5 = list_create();
  99.  
  100. if(list_5->tail != NULL) {
  101. printf("list_5->head is supposed to be NULL\n but isn't");
  102. return 1;
  103. }
  104. printf("Task 5 Passed\n");
  105.  
  106.  
  107. //Task 6
  108. printf("Testing Task 6\n");
  109. list_t* list_6 = list_create();
  110. list_print(list_6);
  111. printf("Task 6 Passed\n");
  112.  
  113. //get rid of arrays
  114. list_destroy(list);
  115. list_destroy(list_2);
  116. list_destroy(list_3);
  117. list_destroy(list_4);
  118. list_destroy(list_5);
  119. list_destroy(list_6);
  120.  
  121. printf("Tasks 2 to 6 have all passed\n");
  122. return 0;
  123. }
  124.  
  125.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.c: In function 'main':
prog.c:7:2: error: unknown type name 'list_t'
  list_t* list = list_create();
  ^
prog.c:7:17: warning: implicit declaration of function 'list_create' [-Wimplicit-function-declaration]
  list_t* list = list_create();
                 ^
prog.c:7:17: warning: initialization makes pointer from integer without a cast [-Wint-conversion]
prog.c:9:3: warning: implicit declaration of function 'list_append' [-Wimplicit-function-declaration]
   list_append(list, i);
   ^
prog.c:11:3: warning: implicit declaration of function 'list_prepend' [-Wimplicit-function-declaration]
   list_prepend(list, i);
   ^
prog.c:13:2: warning: implicit declaration of function 'list_print' [-Wimplicit-function-declaration]
  list_print(list);
  ^
prog.c:15:2: error: unknown type name 'element_t'
  element_t* el_1 = list_index(list, index);
  ^
prog.c:15:20: warning: implicit declaration of function 'list_index' [-Wimplicit-function-declaration]
  element_t* el_1 = list_index(list, index);
                    ^
prog.c:15:20: warning: initialization makes pointer from integer without a cast [-Wint-conversion]
prog.c:20:49: error: request for member 'val' in something not a structure or union
  printf("value at index %d is %d\n", index, el_1->val);
                                                 ^
prog.c:23:9: error: request for member 'val' in something not a structure or union
  if(el_1->val != -2) 
         ^
prog.c:31:2: error: unknown type name 'element_t'
  element_t* el_2 = element_create(9);
  ^
prog.c:31:20: warning: implicit declaration of function 'element_create' [-Wimplicit-function-declaration]
  element_t* el_2 = element_create(9);
                    ^
prog.c:31:20: warning: initialization makes pointer from integer without a cast [-Wint-conversion]
prog.c:32:9: error: request for member 'val' in something not a structure or union
  if(el_2->val != 9) {
         ^
prog.c:42:2: error: unknown type name 'element_t'
  element_t* el_3 = element_create(99);
  ^
prog.c:42:20: warning: initialization makes pointer from integer without a cast [-Wint-conversion]
  element_t* el_3 = element_create(99);
                    ^
prog.c:43:2: error: unknown type name 'list_t'
  list_t* list_2 = list_create();
  ^
prog.c:43:19: warning: initialization makes pointer from integer without a cast [-Wint-conversion]
  list_t* list_2 = list_create();
                   ^
prog.c:48:10: error: request for member 'tail' in something not a structure or union
  if (list->tail->val != 4){
          ^
prog.c:53:6: error: request for member 'next' in something not a structure or union
  el_3->next = list_index(list_2, 3);
      ^
prog.c:54:11: error: request for member 'next' in something not a structure or union
  free(el_3->next);
           ^
prog.c:55:7: warning: assignment makes pointer from integer without a cast [-Wint-conversion]
  el_3 = element_create(100);
       ^
prog.c:56:9: error: request for member 'next' in something not a structure or union
  if(el_3->next != NULL){
         ^
prog.c:67:2: error: unknown type name 'list_t'
  list_t* list_3 = list_create();
  ^
prog.c:67:19: warning: initialization makes pointer from integer without a cast [-Wint-conversion]
  list_t* list_3 = list_create();
                   ^
prog.c:68:2: error: unknown type name 'element_t'
  element_t* el_4 = list_index(list_3, 5);
  ^
prog.c:68:20: warning: initialization makes pointer from integer without a cast [-Wint-conversion]
  element_t* el_4 = list_index(list_3, 5);
                    ^
prog.c:80:2: error: unknown type name 'list_t'
  list_t* list_4 = list_create();
  ^
prog.c:80:19: warning: initialization makes pointer from integer without a cast [-Wint-conversion]
  list_t* list_4 = list_create();
                   ^
prog.c:82:11: error: request for member 'tail' in something not a structure or union
  if(list_4->tail->val != 800) {
           ^
prog.c:93:2: error: unknown type name 'list_t'
  list_t* list_5 = list_create();
  ^
prog.c:93:19: warning: initialization makes pointer from integer without a cast [-Wint-conversion]
  list_t* list_5 = list_create();
                   ^
prog.c:94:8: error: request for member 'head' in something not a structure or union
  list_5->head = element_create(666);
        ^
prog.c:95:8: error: request for member 'head' in something not a structure or union
  list_5->head->next = element_create(333);
        ^
prog.c:96:8: error: request for member 'tail' in something not a structure or union
  list_5->tail = list_5->head->next;
        ^
prog.c:96:23: error: request for member 'head' in something not a structure or union
  list_5->tail = list_5->head->next;
                       ^
prog.c:98:9: warning: assignment makes pointer from integer without a cast [-Wint-conversion]
  list_5 = list_create();
         ^
prog.c:100:11: error: request for member 'tail' in something not a structure or union
  if(list_5->tail != NULL) {
           ^
prog.c:109:2: error: unknown type name 'list_t'
  list_t* list_6 = list_create();
  ^
prog.c:109:19: warning: initialization makes pointer from integer without a cast [-Wint-conversion]
  list_t* list_6 = list_create();
                   ^
prog.c:114:2: warning: implicit declaration of function 'list_destroy' [-Wimplicit-function-declaration]
  list_destroy(list);
  ^
stdout
Standard output is empty