Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //
- // task.c
- // skuska 2
- //
- // Created by Martin Senitka on 24/05/16.
- // Copyright © 2016 Martin Senitka. All rights reserved.
- //
- #include "task.h"
- #include <stdlib.h>
- #include <string.h>
- struct task* add_task(struct task* first, struct task* new){
- if(first == NULL){
- first=new;
- return first;
- }
- struct task* pom = first;
- while(pom->next!=NULL){
- pom = pom->next;
- }
- pom->next = new;
- return first;
- }
- struct task* create_task(char* description,bool active){
- if (description == NULL || strlen(description)==0) {
- return NULL;
- }
- struct task* akt = (struct task*)calloc(1, sizeof(struct task));
- akt->description=description;
- akt->active=active;
- akt->next=NULL;
- return akt;
- }
- bool is_active(struct task* task){
- if(task==NULL){
- return false;
- }
- else{
- return task->active;
- }
- }
- void set_task_active(struct task* task){
- if(task==NULL){
- return;
- }else{
- task->active=true;
- }
- }
- void set_task_inactive(struct task* task){
- if(task == NULL){
- return;
- }else{
- task->active=false;
- }
- }
- struct task* delete_completed(struct task* first){
- if(first==NULL){
- return NULL;
- }
- //mazanie zaciatku
- struct task* akt = first;
- struct task* prev;
- while (first!=NULL && first->active==false) {
- akt=first;
- first=akt->next;
- /*if (akt->description!=NULL) {
- free(akt->description);
- }*/
- free(akt);
- }
- if (first==NULL) {
- return NULL;
- }
- prev =first;
- akt= first->next;
- while (akt!=NULL) {
- if (akt->active==false) {
- prev->next = akt->next;
- /*if (akt->description==NULL) {
- free(akt->description);
- }*/
- free(akt);
- akt=prev->next;
- }else{
- prev=akt;
- akt=akt->next;
- }
- }
- return first;
- }
- void print_tasks(struct task* first){
- if (first== NULL) {
- return;
- }
- struct task* akt = first;
- printf("\n ZOZNAM ULOH: \n");
- while (akt!=NULL ) {
- printf(" %s\n", akt->description);
- akt=akt->next;
- }
- }
Add Comment
Please, Sign In to add comment