Guest User

Untitled

a guest
May 24th, 2016
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.60 KB | None | 0 0
  1. //
  2. // task.c
  3. // skuska 2
  4. //
  5. // Created by Martin Senitka on 24/05/16.
  6. // Copyright © 2016 Martin Senitka. All rights reserved.
  7. //
  8.  
  9. #include "task.h"
  10. #include <stdlib.h>
  11. #include <string.h>
  12.  
  13. struct task* add_task(struct task* first, struct task* new){
  14.  
  15.  
  16. if(first == NULL){
  17.  
  18. first=new;
  19. return first;
  20. }
  21.  
  22. struct task* pom = first;
  23.  
  24. while(pom->next!=NULL){
  25.  
  26. pom = pom->next;
  27.  
  28. }
  29.  
  30. pom->next = new;
  31.  
  32. return first;
  33. }
  34.  
  35.  
  36.  
  37. struct task* create_task(char* description,bool active){
  38.  
  39. if (description == NULL || strlen(description)==0) {
  40. return NULL;
  41. }
  42.  
  43. struct task* akt = (struct task*)calloc(1, sizeof(struct task));
  44.  
  45.  
  46. akt->description=description;
  47.  
  48. akt->active=active;
  49.  
  50. akt->next=NULL;
  51.  
  52.  
  53. return akt;
  54. }
  55.  
  56.  
  57.  
  58. bool is_active(struct task* task){
  59.  
  60.  
  61. if(task==NULL){
  62. return false;
  63. }
  64. else{
  65.  
  66. return task->active;
  67. }
  68.  
  69. }
  70.  
  71.  
  72. void set_task_active(struct task* task){
  73.  
  74.  
  75. if(task==NULL){
  76. return;
  77.  
  78. }else{
  79.  
  80. task->active=true;
  81. }
  82.  
  83.  
  84.  
  85. }
  86.  
  87.  
  88. void set_task_inactive(struct task* task){
  89.  
  90. if(task == NULL){
  91. return;
  92. }else{
  93.  
  94. task->active=false;
  95. }
  96.  
  97. }
  98.  
  99. struct task* delete_completed(struct task* first){
  100.  
  101. if(first==NULL){
  102. return NULL;
  103. }
  104.  
  105. //mazanie zaciatku
  106. struct task* akt = first;
  107. struct task* prev;
  108.  
  109. while (first!=NULL && first->active==false) {
  110. akt=first;
  111. first=akt->next;
  112. /*if (akt->description!=NULL) {
  113. free(akt->description);
  114. }*/
  115. free(akt);
  116. }
  117.  
  118.  
  119. if (first==NULL) {
  120. return NULL;
  121. }
  122.  
  123. prev =first;
  124. akt= first->next;
  125.  
  126. while (akt!=NULL) {
  127.  
  128. if (akt->active==false) {
  129. prev->next = akt->next;
  130. /*if (akt->description==NULL) {
  131. free(akt->description);
  132. }*/
  133. free(akt);
  134. akt=prev->next;
  135. }else{
  136. prev=akt;
  137. akt=akt->next;
  138.  
  139. }
  140.  
  141.  
  142. }
  143.  
  144. return first;
  145.  
  146. }
  147.  
  148.  
  149. void print_tasks(struct task* first){
  150.  
  151. if (first== NULL) {
  152. return;
  153. }
  154.  
  155. struct task* akt = first;
  156.  
  157. printf("\n ZOZNAM ULOH: \n");
  158.  
  159. while (akt!=NULL ) {
  160. printf(" %s\n", akt->description);
  161. akt=akt->next;
  162. }
  163.  
  164.  
  165.  
  166. }
Add Comment
Please, Sign In to add comment