Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include "estruturas.h"
- #include "funcoes.h"
- void insere_lista_user(lista_users lista, char *username,char *password, char *data_nascimento, char *morada, char *telefone)
- {
- lista_users no;
- lista_users ant, inutil;
- no = (lista_users) malloc (sizeof (USERS));
- if (no != NULL)
- {
- strcpy(no->username,username);
- strcpy(no->password,password);
- strcpy(no->data_nascimento,data_nascimento);
- strcpy(no->morada,morada);
- strcpy(no->telefone,telefone);
- procura_lista_user(lista, username, &ant, &inutil);
- no->info_pdi = inicia_lista_pdis_users();
- no->next = ant ->next;
- ant->next = no;
- }
- }
- void procura_lista_user (lista_users lista, char *chave, lista_users *ant, lista_users *atual)
- {
- *ant = lista;
- *atual = lista -> next;
- while ((*atual) != NULL &&( strcmp((*atual)->username, chave) < 0))
- {
- *ant = *atual;
- *atual = (*atual) -> next;
- }
- while ((*atual) != NULL &&( strcmp((*atual)->username, chave) == 0))
- {
- *atual = NULL;
- }
- if ((*atual) != NULL && (strcmp((*atual)->username, chave) != 0))
- {
- *atual = NULL;
- }
- }
- lista_users inicia_lista_users(void){
- lista_users aux;
- aux = (lista_users) malloc(sizeof(USERS));
- if (aux != NULL) {
- aux->username[0] = '\0';
- aux->password[0] = '\0';
- aux->data_nascimento[0] = '\0';
- aux->morada[0] = '\0';
- aux->telefone[0] = '\0';
- aux->next = NULL;
- aux->info_pdi = inicia_lista_pdis_users();
- }
- return aux;
- }
- int check_local(lista_locais lista, char *it){
- lista_locais ptr = lista->next;
- while(ptr!= NULL)
- {
- if (strcmp(ptr->nome, it) == 0)
- return 1;
- ptr=ptr->next;
- }
- return 0;
- }
- int check_pdi(lista_pdi lista, char *it){
- lista_pdi ptr = lista->next;
- while(ptr!= NULL)
- {
- if (strcmp(ptr->nome, it) == 0)
- return 1;
- ptr=ptr->next;
- }
- return 0;
- }
- void insere_lista_pdis(lista_pdi lista, char *it, char *npdi, char* dpdi, char* hpdi,int inscritos) {
- lista_pdi no,ant,inutil;
- no = (lista_pdi) malloc(sizeof(PDI));
- if (no != NULL) {
- strcpy(no->descricao,dpdi);
- strcpy(no->horario,hpdi);
- strcpy(no->nome,npdi);
- no->n_inscritos_pdi = inscritos;
- procura_lista_pdis(lista,npdi,&ant,&inutil);
- no->next = ant->next;
- ant->next = no;
- }
- }
- void insere_lista_locais(lista_locais lista, char *it, char *npdi, char* dpdi, char* hpdi,int local_inscritos,int pdi_inscritos)
- {
- lista_locais no;
- lista_locais ant,inutil;
- no = (lista_locais) malloc (sizeof(LOCAIS));
- if (no != NULL)
- {
- if(check_local(lista,it)==0) {
- strcpy(no->nome,it);
- no->n_inscritos_local = local_inscritos;
- procura_lista_locais(lista, it, &ant, &inutil);
- no->next = ant->next;
- ant->next = no;
- no->lista_pdi_local = inicia_lista_pdis();
- insere_lista_pdis(no->lista_pdi_local,it,npdi,dpdi,hpdi,pdi_inscritos);
- }else{
- procura_lista_locais(lista, it, &ant, &inutil);
- insere_lista_pdis(ant->lista_pdi_local,it,npdi,dpdi,hpdi,pdi_inscritos);
- /*insere na lista desse local, o pdi"*/
- }
- }
- }
- void procura_lista_pdis(lista_pdi lista, char *chave, lista_pdi *ant, lista_pdi *atual)
- {
- *ant = lista;
- *atual = lista -> next;
- while ((*atual) != NULL &&( strcmp((*atual)->nome, chave) < 0))
- {
- *ant = *atual;
- *atual = (*atual) -> next;
- }
- while ((*atual) != NULL &&( strcmp((*atual)->nome, chave) == 0))
- {
- *ant = *atual;
- *atual = (*atual) -> next;
- }
- if ((*atual) != NULL && (strcmp((*atual)->nome, chave) != 0))
- {
- *atual = NULL;
- }
- }
- void procura_pdis_inscritos(lista_pdi lista, int chave, lista_pdi *ant, lista_pdi *atual)
- {
- *ant = lista;
- *atual = lista -> next;
- while ((*atual) != NULL &&( (*atual)->n_inscritos_pdi< chave ))
- {
- *ant = *atual;
- *atual = (*atual) -> next;
- }
- while ((*atual) != NULL &&((*atual)->n_inscritos_pdi == chave))
- {
- *ant = *atual;
- *atual = (*atual) -> next;
- }
- }
- void procura_local_inscritos(lista_locais lista, int chave, lista_locais *ant, lista_locais *atual)
- {
- *ant = lista;
- *atual = lista -> next;
- while ((*atual) != NULL &&( (*atual)->n_inscritos_local>= chave ))
- {
- *ant = *atual;
- *atual = (*atual) -> next;
- }
- while ((*atual) != NULL &&((*atual)->n_inscritos_local != chave))
- {
- *atual = NULL;
- }
- }
- void procura_lista_locais(lista_locais lista, char *chave, lista_locais *ant, lista_locais *atual)
- {
- *ant = lista;
- *atual = lista -> next;
- while ((*atual) != NULL &&( strcmp((*atual)->nome, chave) < 0))
- {
- *ant = *atual;
- *atual = (*atual) -> next;
- }
- while ((*atual) != NULL &&( strcmp((*atual)->nome, chave) == 0))
- {
- *ant = *atual;
- *atual = (*atual) -> next;
- }
- if ((*atual) != NULL && (strcmp((*atual)->nome, chave) != 0))
- {
- *atual = NULL;
- }
- }
- lista_pdi inicia_lista_pdis(){
- lista_pdi aux;
- aux = (lista_pdi) malloc(sizeof(PDI));
- if (aux != NULL) {
- aux->nome[0] = '\0';
- aux->descricao[0] = '\0';
- aux->horario[0] = '\0';
- aux->next = NULL;
- }
- return aux;
- }
- lista_users_pdi inicia_lista_pdis_users(){
- lista_users_pdi aux;
- aux = (lista_users_pdi)malloc(sizeof(PDI_USERS));
- if (aux != NULL) {
- aux->pdi = NULL;
- aux->next = NULL;
- }
- return aux;
- }
- lista_locais inicia_lista_locais(void){
- lista_locais aux;
- aux = (lista_locais) malloc(sizeof(LOCAIS));
- if (aux != NULL) {
- aux->nome[0] = '\0';
- aux->next = NULL;
- }
- return aux;
- }
- void imprimir_lista_locais_pdis(lista_locais auxLocais){
- lista_locais l = auxLocais->next; /* para saltar o header e nao apresentar o primeiro elemento criado pelo cria_lista() */
- while(l->next){
- printf("%s - %d inscritos\n-----\n", l->nome,l->n_inscritos_local);
- lista_pdi u = l->lista_pdi_local->next;
- while(u) {
- printf("%s - %d inscritos - %s - %s\n", u->nome,u->n_inscritos_pdi,u->descricao,u->horario);
- u = u->next;
- }
- printf("\n------\n");
- l=l->next;
- }
- }
- void imprimir_lista_pdis(lista_locais auxLocais){
- lista_locais l = auxLocais->next; /* para saltar o header e nao apresentar o primeiro elemento criado pelo cria_lista() */
- while(l){
- lista_pdi u = l->lista_pdi_local->next;
- while(u) {
- printf("%s - %d inscritos - %s - %s\n", u->nome,u->n_inscritos_pdi,u->descricao,u->horario);
- u = u->next;
- }
- free(u);
- l=l->next;
- }
- }
- void imprimir_lista_locais(lista_locais auxLocais){
- lista_locais l = auxLocais->next; /* para saltar o header e nao apresentar o primeiro elemento criado pelo cria_lista() */
- while(l){
- printf("%s , %d inscritos\n-----\n", l->nome,l->n_inscritos_local);
- l=l->next;
- }
- }
- void imprimir_lista_users(lista_users auxpdis){
- lista_users l = auxpdis->next; /* para saltar o header e nao apresentar o primeiro elemento criado pelo cria_lista() */
- while(l){
- printf("Nome: %s\n",l->username);
- printf("Password: %s\n",l->password);
- printf("Data Nascimento: %s\n",l->data_nascimento);
- printf("Morada: %s\n",l->morada);
- printf("Telefone: %s\n",l->telefone);
- printf("PDI HOT: %s\n",l->pdi_hot->nome);
- printf("Local 1: %s\n",l->array_locais[0]->nome);
- printf("Local 2: %s\n",l->array_locais[1]->nome);
- printf("Local 3: %s\n",l->array_locais[2]->nome);
- printf("--------\n");
- l=l->next;
- }
- }
- void alterar_dados_password(lista_users users,char *user_logado,char *password,char *data,char *morada,char *tele){
- lista_users ptr = users->next;
- while(ptr != NULL)
- {
- if (strcmp(ptr->username, user_logado) == 0){
- if(password != NULL)
- strcpy(ptr->password,password);
- if(data != NULL)
- strcpy(ptr->data_nascimento,data);
- if(morada != NULL)
- strcpy(ptr->morada,morada);
- if(tele != NULL)
- strcpy(ptr->telefone,tele);
- }
- ptr=ptr->next;
- }
- }
- void load_users(lista_users auxUser,lista_locais locais){
- FILE *fp;
- char buffer[MAX];
- char auxUsername[MAX];
- char auxPassword[MAX];
- char auxData_nascimento[MAX];
- char auxMorada[MAX];
- char auxTelefone[MAX];
- char local[MAX];
- char pdi_hot_name[MAX];
- char pdi_name[MAX];
- int pdihot = 0, pdis = 0 , loc = 0, novo = 0;
- if ((fp=fopen("users.txt", "r")) == NULL){
- printf ("Erro ao abrir o ficheiro de utilizadores.\n");
- exit(1);
- }
- while (!feof(fp)){
- fgets(buffer, MAX, fp);
- if(strcmp(buffer, "--LOCAIS\n") == 0){
- novo = 0;
- loc = 1;
- pdis = 0;
- pdihot = 0;
- continue;
- }
- if(strcmp(buffer, "--PDI\n") == 0){
- novo = 0;
- loc = 0;
- pdis = 1;
- pdihot = 0;
- continue;
- }
- if(strcmp(buffer, "--PDIHOT\n") == 0){
- novo = 0;
- loc = 0;
- pdis = 0;
- pdihot = 1;
- continue;
- }
- if(strcmp(buffer, "---\n") == 0){
- novo=1;
- loc=0;
- pdihot=0;
- pdis=0;
- continue;
- }
- if(novo){
- strcpy(auxUsername, strtok(buffer, "-"));
- strcpy(auxPassword, strtok(NULL, "-"));
- strcpy(auxData_nascimento, strtok(NULL, "-"));
- strcpy(auxMorada, strtok(NULL, "-"));
- strcpy(auxTelefone, strtok(NULL, "-"));
- insere_lista_user(auxUser,auxUsername,auxPassword,auxData_nascimento,auxMorada,auxTelefone);
- }
- if(pdihot){
- strcpy(pdi_hot_name, strtok(buffer, "-"));
- load_pref_pdihot(auxUser,locais,auxUsername,pdi_hot_name);
- }
- if(loc){
- strcpy(local, strtok(buffer, "-"));
- load_pref_local(auxUser,locais,auxUsername,local);
- }/*
- if(pdis){
- strcpy(pdi_name, strtok(buffer, "-"));
- load_pref_pdi(auxUser,locais,auxUsername,pdi_name);
- }*/
- }
- fclose(fp);
- }
- void load_pref_pdi(lista_users lista_u,lista_locais locais,char *username, char *pdi_name){
- lista_users inutil_user,ant_user;
- lista_users_pdi aux_pdi,novo_no;
- lista_locais aux2;
- procura_lista_user(lista_u,username,&ant_user,&inutil_user);
- aux_pdi = ant_user->info_pdi;
- aux2 = locais->next;
- while(aux2) {
- lista_pdi u = aux2->lista_pdi_local->next;
- while (u) {
- if (strcmp(u->nome, pdi_name) == 0) {
- novo_no = (lista_users_pdi) malloc(sizeof(PDI_USERS));
- novo_no->pdi = u;
- novo_no->next= NULL;
- while (aux_pdi->next != NULL){
- aux_pdi = aux_pdi->next;
- }
- aux_pdi->next =novo_no;
- novo_no->next = NULL;
- }
- u = u->next;
- }
- free(u);
- aux2 = aux2->next;
- }
- free(aux2);
- }
- void load_pref_pdihot(lista_users lista_u,lista_locais locais,char *username , char * pdi_hot_name){
- lista_users inutil_user,ant_user,aux_user_hot;
- lista_locais aux2;
- procura_lista_user(lista_u,username,&ant_user,&inutil_user);
- aux2 = locais->next;
- aux_user_hot = ant_user;
- while(aux2!=NULL) {
- lista_pdi u = aux2->lista_pdi_local->next;
- while (u) {
- if (strcmp(u->nome, pdi_hot_name) == 0) {
- PDI *novo_no_hot = u;
- aux_user_hot->pdi_hot = novo_no_hot;
- }
- u = u->next;
- }
- free(u);
- aux2 = aux2->next;
- }
- }
- void load_pref_local(lista_users lista_u,lista_locais locais,char *username,char *nomelocal){
- lista_users inutil_user,ant_user,user_aux;
- lista_locais ant,inutil;
- int counter = 0;
- procura_lista_user(lista_u,username,&ant_user,&inutil_user);
- user_aux = ant_user;
- while (counter!= 3) {
- if (check_local(locais, nomelocal) == 1) {
- procura_lista_locais(locais, nomelocal, &ant, &inutil);
- user_aux->array_locais[counter] = ant;
- /*lista_u->array_locais[counter]->next = NULL;*/
- counter++;
- } else {
- printf("Local não existe, escolha outro\n");
- }
- }
- }
- void load_locais(lista_locais auxLocal){
- FILE *fp;
- int a,b;
- char buffer[MAX];
- char auxname[MAX];
- char aux_pdi_name[MAX];
- char aux_pdi_type[MAX];
- char n_inscritos_local[MAX];
- char n_inscritos_pdi[MAX];
- char aux_schedule[MAX];
- if ((fp=fopen("locaisepdis.txt", "r")) == NULL){
- printf ("Erro ao abrir o ficheiro de locais e pdi's.\n");
- exit(1);
- }else{
- while (!feof(fp)){
- fgets(buffer, MAX, fp);
- strcpy(auxname, strtok(buffer, "-"));
- strcpy(n_inscritos_local, strtok(NULL, ";"));
- a= atoi(n_inscritos_local);
- strcpy(aux_pdi_name, strtok(NULL, ";"));
- strcpy(aux_pdi_type, strtok(NULL, ";"));
- strcpy(aux_schedule, strtok(NULL, ";"));
- strcpy(n_inscritos_pdi, strtok(NULL, ";"));
- b = atoi(n_inscritos_pdi);
- insere_lista_locais(auxLocal,auxname,aux_pdi_name,aux_pdi_type,aux_schedule,a,b);
- }
- fclose(fp);
- }
- }
- /*BUBBLE SORT PARA PDIS E LOCAIS (POR ORDEM ALFABETICA E POR N INSCRITOS)*/
- void ordena_pdis(lista_locais auxLocais){
- lista_locais l = auxLocais->next;
- while(l->next){
- lista_pdi d = l->lista_pdi_local->next;
- int n_nos=0;
- n_nos = nNosPdi(d);
- l=l->next;
- }
- }
- void ordena_pdis_Char(lista_locais auxLocais){
- lista_locais l = auxLocais->next;
- while(l){
- lista_pdi u = l->lista_pdi_local->next;
- int n_nos=0;
- n_nos = nNosPdi(u);
- bubbleSortCharPdi(&u,n_nos);
- l=l->next;
- }
- }
- lista_locais trocaNos(lista_locais ptr1, lista_locais ptr2)
- {
- lista_locais tmp = ptr2->next;
- ptr2->next = ptr1;
- ptr1->next = tmp;
- return ptr2;
- }
- lista_pdi trocaNosPdi(lista_pdi ptr1, lista_pdi ptr2)
- {
- lista_pdi tmp = ptr2->next;
- ptr2->next = ptr1;
- ptr1->next = tmp;
- return ptr2;
- }
- int nNos(lista_locais head)
- {
- int count = 0;
- lista_locais atual = head;
- while (atual != NULL)
- {
- count++;
- atual = atual->next;
- }
- return count;
- }
- int nNosPdi(lista_pdi head)
- {
- int count = 0;
- lista_pdi atual = head;
- while (atual != NULL)
- {
- count++;
- atual = atual->next;
- }
- return count;
- }
- void bubbleSort(lista_locais * head, int count)
- {
- lista_locais* h;
- int i, j, troca;
- for (i = 0; i <= count; i++) {
- h = head;
- troca = 0;
- for (j = 0; j < count - i - 1; j++) {
- lista_locais p1 = *h;
- lista_locais p2 = p1->next;
- if (p1->n_inscritos_local > p2->n_inscritos_local) {
- *h = trocaNos(p1, p2);
- troca = 1;
- }
- h = &(*h)->next;
- }
- if (troca == 0)
- break;
- }
- }
- void bubbleSortPdi(lista_pdi * head, int count)
- {
- lista_pdi* h;
- int i, j, troca;
- for (i = 0; i <= count; i++) {
- h = head;
- troca = 0;
- for (j = 0; j < count - i - 1; j++) {
- lista_pdi p1 = *h;
- lista_pdi p2 = p1->next;
- if (p1->n_inscritos_pdi > p2->n_inscritos_pdi) {
- *h = trocaNosPdi(p1, p2);
- troca = 1;
- }
- h = &(*h)->next;
- }
- if (troca == 0)
- break;
- }
- }
- void bubbleSortChar(lista_locais * head, int count)
- {
- lista_locais* h;
- int i, j, troca;
- for (i = 0; i <= count; i++) {
- h = head;
- troca = 0;
- for (j = 0; j < count - i - 1; j++) {
- lista_locais p1 = *h;
- lista_locais p2 = p1->next;
- if (strcmp(p1->nome,p2->nome)>0) {
- *h = trocaNos(p1, p2);
- troca = 1;
- }
- h = &(*h)->next;
- }
- if (troca == 0)
- break;
- }
- }
- void bubbleSortCharPdi(lista_pdi * head, int count)
- {
- lista_pdi* h;
- int i, j, troca;
- for (i = 0; i <= count; i++) {
- h = head;
- troca = 0;
- for (j = 0; j < count - i - 1; j++) {
- lista_pdi p1 = *h;
- lista_pdi p2 = p1->next;
- if (strcmp(p1->nome,p2->nome)>0) {
- *h = trocaNosPdi(p1, p2);
- troca = 1;
- }
- h = &(*h)->next;
- }
- if (troca == 0)
- break;
- }
- }
- /*FIM DAS FUNCOES PARA O SORT*/
- void login_registo(lista_users auxUser,lista_locais locais){
- FILE *fp;
- char uName[MAX];
- char pWord[MAX];
- char dNascimento[MAX];
- char morada[MAX];
- char telefone[MAX];
- int i;
- lista_users l;
- l = auxUser->next; /* para saltar o header */
- printf("VIAGEM DO DEI \n----------------------\n");
- printf("1. Login \n");
- printf("2. Registar\n");
- scanf("%d",&i);
- getchar();
- clear();
- switch(i){
- case 1:
- printf("Username: ");
- scanf("%s",uName);
- printf("Password: ");
- scanf("%s",pWord);
- while(l){
- if(strcmp(l->username, uName) == 0) {
- if(strcmp(l->password, pWord) == 0) {
- printf ("Dados Corretos. Login feito.\n");
- clear();
- menu(locais,auxUser,uName);
- }
- }
- l=l->next;
- }
- clear();
- printf("Dados incorretos. Tente novamente.\n");
- login_registo(auxUser,locais);
- break;
- case 2:
- if ( ( fp=fopen("users.txt", "a+")) == NULL){
- printf ("ERRO AO ABRIR O FICHEIRO\n");
- exit(1);
- }
- printf("Indique os dados para completar o registo:\n");
- printf("Username: ");
- scanf("%s",uName);
- printf("Password: ");
- scanf("%s",pWord);
- printf("Data nascimento: ");
- scanf("%s",dNascimento);
- printf("Morada: ");
- scanf(" %[^\n]s", morada);
- printf("Telefone: ");
- scanf("%s",telefone);
- insere_lista_user(auxUser,uName,pWord,dNascimento,morada,telefone);
- clear();
- menu(locais,auxUser,uName);
- break;
- default:
- login_registo(auxUser,locais);
- }
- free(auxUser);
- free(locais);
- fclose(fp);
- }
- void escreve_users_ficheiro(lista_users auxUser){
- lista_users l = auxUser->next;
- FILE *fp;
- if ( ( fp=fopen("users.txt", "w")) == NULL){
- printf ("ERRO AO ABRIR O FICHEIRO\n");
- exit(1);
- }
- while(l!=NULL){
- if(l->next == NULL)
- fprintf(fp,"%s-%s-%s-%s-%s-",l->username,l->password,l->data_nascimento,l->morada,l->telefone);
- else
- fprintf(fp,"%s-%s-%s-%s-%s-\n",l->username,l->password,l->data_nascimento,l->morada,l->telefone);
- l=l->next;
- }
- fclose(fp);
- }
- void alterar_dados_utilizador(lista_locais locais,lista_users users,char * user_logado){
- int opcao2;
- char var[MAX];
- clear();
- printf("Alterar dados utilizador.\n -------------\n");
- printf("Nome de utilizador: %s\n -------------\n",user_logado);
- printf("Escolha a sua opcao \n");
- printf("1 - Alterar password.\n");
- printf("2 - Alterar data nascimento.\n");
- printf("3 - Alterar morada.\n");
- printf("4 - Alterar telefone.\n");
- printf("5 - Retroceder\n");
- scanf("%d",&opcao2);
- getchar();/*Para receber o enter e avançar*/
- clear();
- switch(opcao2){
- case 1:
- clear();
- printf("Nova password: ");
- scanf("%s",var);
- alterar_dados_password(users,user_logado,var,NULL,NULL,NULL);
- printf("Pressione enter para voltar\n");
- getchar();
- break;
- case 2:
- clear();
- printf("Nova data de nascimento: ");
- scanf("%s",var);
- alterar_dados_password(users,user_logado,NULL,var,NULL,NULL);
- printf("Pressione enter para voltar\n");
- getchar();
- break;
- case 3:
- clear();
- printf("Nova morada:");
- scanf("%s",var);
- alterar_dados_password(users,user_logado,NULL,NULL,var,NULL);
- printf("Pressione enter para voltar\n");
- getchar();
- break;
- case 4:
- clear();
- printf("Novo telefone:");
- scanf("%s",var);
- alterar_dados_password(users,user_logado,NULL,NULL,NULL,var);
- printf("Pressione enter para voltar\n");
- getchar();
- break;
- case 5:
- clear();
- menu(locais,users,user_logado);
- }
- alterar_dados_utilizador(locais,users,user_logado);
- }
- void insere_preferencias_user(lista_users users,lista_locais locais, char *user_logado){
- int opcao3;
- printf("Adicionar preferencias de utilizador\n -------------\n");
- printf("Escolha a sua opcao \n");
- printf("1 - Inserir 3 locais\n");
- printf("2 - Inserir PDI's\n");
- printf("3 - Inserir PDI HOT\n");
- printf("4 - Retroceder\n");
- scanf("%d",&opcao3);
- getchar();/*Para receber o enter e avançar*/
- clear();
- switch(opcao3){
- case 1:
- clear();
- imprimir_lista_locais(locais);
- int i=0;
- char local[MAX];
- while(i!=3){
- printf("Nome do Local : ");
- scanf(" %[^\n]s", local);
- load_pref_local(users,locais,user_logado,local);
- i++;
- }
- break;
- case 2:
- clear();
- imprimir_lista_locais_pdis(locais);
- int j=0;
- printf("Quantos PDI's pretende inserir?\n");
- scanf("%d",&j);
- char pdi_aux[MAX];
- while(j!=0){
- printf("Nome do PDI : ");
- scanf(" %[^\n]s", pdi_aux);
- load_pref_pdi(users,locais,user_logado,pdi_aux);
- j--;
- }
- break;
- case 3:
- clear();
- imprimir_lista_locais_pdis(locais);
- char pdihot[MAX];
- printf("Nome do PDI HOT : ");
- scanf(" %[^\n]s", pdihot);
- load_pref_pdi(users,locais,user_logado,pdihot);
- break;
- case 4:
- clear();
- menu(locais,users,user_logado);
- break;
- default:
- insere_preferencias_user(users,locais,user_logado);
- }
- }
- /*FUNCOES PARA SIMPLIFICAR MENU*/
- void clear(){
- system("@cls||clear"); /*Clear para o terminal do windows*/
- }
- void voltar_menu(){
- printf("Prima Enter para voltar ao menu.");
- getchar();
- clear();
- }
- /*
- MENU
- */
- void menu(lista_locais locais,lista_users users,char * user_logado)
- {
- int opcao,opcao3;
- lista_users ant,inutil;
- printf("MENU PRINCIPAL \n----------------------\n");
- printf("Escolha a sua opcao \n");
- printf("1 - Alterar dados utilizador.\n");
- printf("2 - Listagem por ordem alfabetica.\n");
- printf("3 - Adicionar preferencias de utilizador.\n");
- printf("4 - Remover preferencias de utilizador.\n");
- printf("5 - Listagem por popularidade.\n");
- printf("6 - Gerar Viagem.\n");
- printf("7 - Terminar o programa.\n");
- scanf("%d",&opcao);
- getchar();/*Para receber o enter e avançar*/
- clear();
- switch(opcao){
- case 1:
- alterar_dados_utilizador(locais,users,user_logado);
- case 2:
- clear();
- printf("Listagem por ordem alfabetica\n -------------\n");
- int list_size2 = nNos(locais);
- bubbleSortChar(&locais,list_size2);
- ordena_pdis_Char(locais);
- imprimir_lista_locais_pdis(locais);
- voltar_menu();
- break;
- case 3:
- clear();
- insere_preferencias_user(users,locais,user_logado);
- voltar_menu();
- break;
- case 4:
- clear();
- printf("Remover preferencias de utilizador\n -------------\n");
- voltar_menu();
- break;
- case 5:
- clear();
- printf("Listagem por popularidade\n -------------\n");
- int list_size = nNos(locais);
- bubbleSort(&locais,list_size);
- ordena_pdis(locais);
- imprimir_lista_locais_pdis(locais);
- voltar_menu();
- break;
- case 6:
- clear();
- printf("Gerar Viagem\n -------------\n");
- voltar_menu();
- break;
- case 7:
- escreve_users_ficheiro(users);
- clear();
- printf("Programa terminado\n");
- exit(0);
- break;
- }
- menu(locais,users,user_logado);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement