Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include "header.h"
- int main(){
- ListP listaPessoa;
- listaPessoa = cria_listaPessoa();
- //loadPessoa(listaPessoa);
- ListT listaTarefa;
- listaTarefa = cria_listaTarefa();
- ListTD listaTD, listaDone;
- listaTD = cria_listaTodo();
- listaDone = cria_listaTodo();
- ListD listaDoing;
- listaDoing = cria_listaDoing();
- int choice;
- a:
- choice = menu();
- switch(choice){
- case 1:
- printf("\n\t\t\tLista de Tarefas:\n");
- imprimeLista_Tarefas(listaTarefa);
- printf("\n\t\t\tLista de Pessoas:\n");
- imprimeLista_Pessoas(listaPessoa);
- goto a;
- case 2:
- accao(listaTarefa,listaTD);
- goto a;
- case 3:
- moverDoing(listaTarefa, listaPessoa, listaDoing);
- goto a;
- case 4:
- moverDone(listaTarefa, listaDone);
- goto a;
- case 5:
- removerDone(listaDone);
- goto a;
- case 6:
- printf("\n\t\t\tLista de Tarefas\n");
- imprimeLista_TD(listaTD);
- //imprimeLista_Doing(listaDoing);
- goto a;
- case 7:
- printf("Shutting down...\n");
- exit(0);
- default:
- printf("Escolha invalida\n");
- goto a;
- }
- }
- /*MENU*/
- int menu(){
- int choice;
- printf("\n-----//MENU//-----\n");
- printf("1:Listar Pessoas\n");
- printf("2:Inserir tarefa em To do\n");
- printf("3:Mover cartao para Doing\n");
- printf("4:Mover cartao para Done\n");
- printf("5:Remover cartao de Done\n");
- printf("6:Listar Tarefas\n");
- printf("7:Sair do Programa\n");
- printf("------------------\n");
- printf("O que pretende fazer?\n");
- scanf("%d",&choice);
- return choice;
- }
- /*Criar Listas*/
- ListTD cria_listaTodo(void){
- ListTD aux = (ListTD)malloc(sizeof(List_node_ToDo));
- if(aux!= NULL){
- aux->next = NULL;
- }
- return aux;
- }
- ListD cria_listaDoing(void){
- ListD aux = (ListD)malloc(sizeof(List_node_Doing));
- if(aux!= NULL){
- aux->next = NULL;
- }
- return aux;
- }
- ListT cria_listaTarefa(void){
- ListT aux = (ListT)malloc(sizeof(List_node_cartao));
- if (aux!=NULL){
- aux->next = NULL;
- }
- return aux;
- }
- ListP cria_listaPessoa(void){
- ListP aux = (ListP)malloc(sizeof(List_node_Pessoa));
- if (aux!=NULL){
- aux->next = NULL;
- }
- return aux;
- }
- /*Load Ficheiros de Texto*/
- void loadPessoa(ListP lista){
- FILE *file;
- int idAux;
- char nomeAux[MAX];
- char emailAux[MAX];
- pessoa aux;
- char ch[100];
- file = fopen("pessoas.txt","r");
- while(fscanf(file,"%[^\t\n]",ch) != EOF){
- printf("Entrei\n");
- fseek(file,1,SEEK_CUR);
- idAux = atoi(ch);
- fscanf(file,"%[^\t\n]",nomeAux);
- fseek(file,1,SEEK_CUR);
- fscanf(file,"%[^\t\n]",emailAux);
- fseek(file,2,SEEK_CUR);
- printf("ID Fora do ficheiro: %d\n",idAux);
- printf("Nome Fora do ficheiro: %s\n",nomeAux);
- aux = newPessoa(idAux, nomeAux, emailAux);
- insere_lista_pessoa(lista, aux);
- }
- fclose(file);
- }
- /*Inserções nas Listas*/
- void insere_lista_pessoa(ListP lista, pessoa a){
- printf("\nEntrei e o nome é %s\n", a->nome);
- ListP lst = (ListP) malloc(sizeof(List_node_Pessoa));
- if(lst == NULL){
- printf("ERRO DE ALOCACAO DE MEMORIA\n");
- exit(0);
- }
- printf("Memory created successfully\n");
- ListP aux = lista;
- ListP aux2;
- lst -> pessoa = a;
- if (aux == NULL){
- lista -> next = lst;
- lst -> next = NULL;
- return;
- }
- while (aux){
- aux2 = aux ->next;
- if(aux2 == NULL){
- aux->next = lst;
- lst->next = NULL;
- return;
- }
- aux = aux2;
- }
- }
- void insere_lista_tarefa(ListT lista, cartao a){
- ListT lst = (ListT)malloc(sizeof(List_node_cartao));
- ListT aux = lista;
- ListT aux2;
- lst->cartao = a;
- if(aux==NULL){
- lista->next = lst;
- lst->next = NULL;
- return;
- }
- while(aux){
- aux2 = aux->next;
- if(aux2 == NULL){
- lst->next = NULL;
- aux->next = lst;
- return;
- }
- if(aux2->cartao->prioridade < lst->cartao->prioridade){
- lst->next = aux2;
- aux->next = lst;
- return;
- }
- aux = aux2;
- }
- }
- void insere_lista_todo(ListTD lista, ListTD node){
- ListTD aux = lista;
- ListTD aux2;
- if(aux == NULL){
- lista->next = node;
- node->next = NULL;
- return;
- }
- while(aux){
- aux2 = aux->next;
- if(aux2 == NULL){
- node->next = NULL;
- aux->next = node;
- return;
- }
- aux= aux2;
- }
- }
- void insere_lista_Doing(ListD lista, cartao cartao, ListP listaPessoa){
- pessoa escolhido;
- int id;
- printf("Qual o id da pessoa que pretende associar?\n");
- scanf("%d",&id);
- printf("\n");
- escolhido = procuraListaP(id, listaPessoa);
- ListD node = (ListD)malloc(sizeof(List_node_Doing));
- node->cartao = &cartao;
- node->pessoa = &escolhido;
- ListD aux = lista;
- ListD aux2;
- if(aux == NULL){
- lista->next = node;
- node->next = NULL;
- return;
- }
- while(aux){
- aux2 = aux->next;
- if(aux2 == NULL){
- node->next = NULL;
- aux->next = node;
- return;
- }
- aux= aux2;
- }
- }
- void insere_lista_Done(ListTD lista, cartao tarefa){
- ListTD node = (ListTD)malloc(sizeof(ListTD));
- node->cartao = &tarefa;
- ListTD aux = lista;
- ListTD aux2;
- if(aux == NULL){
- lista->next = node;
- node->next = NULL;
- return;
- }
- while(aux){
- aux2 = aux->next;
- if(aux2 == NULL){
- node->next = NULL;
- aux->next = node;
- return;
- }
- aux= aux2;
- }
- }
- /*Criar Pessoas e Cartões*/
- pessoa newPessoa(int id, char nome[MAX], char email[MAX]){
- printf("Entrei na nova pessoa\n");
- pessoa aux = (pessoa)malloc(sizeof(Pessoa));
- if(aux == NULL){
- printf("Randint foda se\n");
- exit(-1);
- }
- aux->id = id;
- strcpy(aux->nome, nome);
- strcpy(aux->email, email);
- return aux;
- }
- cartao newCartao(int id, int prioridade, char desc[MAX]){
- cartao card = (cartao)malloc(sizeof(cartao));
- if(card == NULL){
- exit(-1);
- }
- card->ID = id;
- card->prioridade = prioridade;
- strcpy(card->descricao, desc);
- return card;
- }
- /*Impressões das Listas*/
- void imprimeLista_Tarefas(ListT lista){
- ListT aux = lista->next;
- while(aux){
- printf("\nTarefa %d\tPrioridade%d\n", aux->cartao->ID, aux->cartao->prioridade);
- aux = aux->next;
- }
- }
- void imprimeLista_Pessoas(ListP lista){
- ListP aux = lista->next;
- while(aux){
- printf("ID: %d\tNome:%s\n", aux->pessoa->id, aux->pessoa->nome);
- aux = aux->next;
- }
- }
- /*TO-DO*/
- void accao(ListT listaTarefa, ListTD listaTodo){
- int id;
- int prioridade;
- char desc[MAX];
- printf("\nID da tarefa:\n");
- scanf("%d", &id);
- printf("\n");
- while(prioridade<0 || prioridade>10){
- printf("\nPrioridade da tarefa(1 a 10):\n");
- scanf("%d", &prioridade);
- printf("\n");
- if(prioridade<0 || prioridade > 10){
- printf("Escolha Inválida, prioridade tem de ser entre 1 e 10\n");
- }
- }
- printf("\nDescricao da tarefa:\n");
- scanf("%s", desc);
- cartao aux = newCartao(id,prioridade, desc);
- insere_lista_tarefa(listaTarefa, aux);
- cartao *pointer = &aux;
- ListTD node = (ListTD)malloc(sizeof(List_node_ToDo));
- node->cartao = pointer;
- insere_lista_todo(listaTodo, node);
- prioridade = 100;
- }
- void moverDoing(ListT listaTarefa, ListP listaPessoa, ListD listaDoing){
- cartao tarefa;
- int choice;
- printf("Qual o ID da tarefa que pretende mover?:\n");
- scanf("%d",&choice);
- printf("tOU AquI\n");
- tarefa = procuraListaT(choice, listaTarefa);
- printf("Encontrei");
- insere_lista_Doing(listaDoing, tarefa, listaPessoa);
- }
- void moverDone(ListT listaTarefa, ListTD listaDone){
- cartao tarefa;
- int choice;
- printf("Qual o ID da tarefa que pretende mover?:\n");
- scanf("%d",&choice);
- printf("tOU AquI\n");
- tarefa = procuraListaT(choice, listaTarefa);
- insere_lista_Done(listaDone, tarefa);
- }
- cartao procuraListaT(int id, ListT listaTarefa){
- ListT aux;
- aux = listaTarefa;
- cartao help;
- help = aux->cartao;
- while(aux){
- if(help->ID != id){
- aux = aux->next;
- }
- else
- break;
- }
- return aux->cartao;
- }
- pessoa procuraListaP(int id, ListP lista){
- ListP aux;
- aux = lista;
- while(aux){
- if(aux->pessoa->id != id){
- aux = aux->next;
- }
- else
- break;
- }
- return aux->pessoa;
- }
- void removerDone(ListTD lista){
- int id;
- printf("Qual o ID da tarefa que pretende remover da lista?\n");
- scanf("%d",&id);
- ListTD node;
- node = popListaD(lista, id);
- free(node);
- }
- ListTD popListaD(ListTD lista, int id){
- ListTD aux = lista;
- ListTD aux2;
- aux = lista;
- aux2 = lista;
- cartao help;
- help = aux->cartao;
- if(help->ID == id){
- aux2 = aux->next;
- lista = aux2;
- return aux;
- }
- aux = aux->next;
- while(aux){
- help = aux->cartao;
- if(help->ID == id){
- aux2->next = aux->next;
- return aux;
- }
- aux2 = aux;
- aux = aux->next;
- }
- }
- void imprimeLista_TD(ListTD lista){
- cartao c;
- ListTD aux = lista->next;
- printf("-\t-\t-\tLISTA TO DO\t-\t-\t-\n");
- while(aux){
- c = aux->cartao;
- printf("\nTarefa: %d\t Prioridade: %d", c->ID, c->prioridade);
- aux = aux->next;
- }
- }
- void imprimeLista_Doing(ListD lista){
- cartao c;
- pessoa p;
- ListD aux = lista;
- printf("-\t-\t-\tLISTA DOING\t-\t-\t-\n");
- while(aux){
- c = aux->cartao;
- p = aux->pessoa;
- printf("\nTarefa:%d\t Prioridade: %d\t Pessoa Associada:%s\n",c->ID, c->prioridade, p->nome);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement