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"
- void clear(){
- system("@cls||clear");
- }
- void voltar_menu(){
- printf("Prima Enter para voltar ao menu.");
- getchar();
- clear();
- }
- /*
- MENU
- */
- void menu()
- {
- int opcao;
- printf("MENU PRINCIPAL \n----------------------\n");
- printf("Escolha a sua opcao \n");
- printf("1 - Listagem por ordem alfabetica.\n");
- printf("2 - Adicionar preferencias de utilizador.\n");
- printf("3 - Remover preferencias de utilizador.\n");
- printf("4 - Listagem por popularidade.\n");
- printf("5 - Gerar Viagem.\n");
- printf("6 - Terminar o programa.\n");
- scanf("%d",&opcao);
- getchar();/*por causa do enter(NAO SEI PQ, mas se n tiver esta merda n da print depois as opcoes)*/
- clear();
- switch(opcao){
- case 1:
- clear();
- printf("Listagem por ordem alfabetica\n -------------\n");
- voltar_menu();
- break;
- case 2:
- clear();
- printf("Adicionar preferencias de utilizador\n -------------\n");
- voltar_menu();
- break;
- case 3:
- clear();
- printf("Remover preferencias de utilizador\n -------------\n");
- voltar_menu();
- break;
- case 4:
- clear();
- printf("Listagem por popularidade\n -------------\n");
- voltar_menu();
- break;
- case 5:
- clear();
- printf("Gerar Viagem\n -------------\n");
- voltar_menu();
- break;
- case 6:
- /*
- ESCREVER FICHEIROS
- */
- clear();
- printf("Programa terminado\n");
- exit(0);
- break;
- }
- menu();
- }
- /*
- LOGIN E REGISTO
- */
- user_ptr create_users_list(){
- user_ptr aux;
- aux = (user_ptr) malloc (sizeof(USERS));
- if (aux != NULL) {
- strcpy(aux->username,NULL);
- strcpy(aux->password,NULL);
- aux->next = NULL;
- }
- return aux;
- }
- void userlogin(user_ptr auxUser){
- FILE *fp;
- char uName[10];
- char pWord[10];
- int i;
- //auxUser=(user_ptr) malloc (sizeof(USERS));
- printf("1. Login \n");
- printf("2. Registar\n");
- scanf("%d",&i);
- switch(i){
- case 1:
- if ( ( fp=fopen("user.txt", "r+")) == NULL) {
- if ( ( fp=fopen("user.txt", "w+")) == NULL) {
- printf ("ERRO AO ABRIR O FICHEIRO\n");
- exit(1);
- }
- }
- printf("Username: ");
- scanf("%s",uName);
- printf("Password: ");
- scanf("%s",pWord);
- while ( fread (auxUser, sizeof(struct user), 1, fp) == 1) {
- if( strcmp ( auxUser->username, uName) == 0) {
- if( strcmp ( auxUser->password, pWord) == 0) {
- printf ("Dados Corretos. Login feito.\n");
- clear();
- menu();
- }else{
- printf("Erro\n");
- }
- }
- }
- break;
- case 2:
- if ( ( fp=fopen("user.txt", "a+")) == NULL) {
- if ( ( fp=fopen("user.txt", "w+")) == NULL) {
- printf ("ERRO AO ABRIR O FICHEIRO\n");
- exit ( 1);
- }
- }
- printf("Choose A Username: ");
- scanf("%s",auxUser->username);
- printf("Choose A Password: ");
- scanf("%s",auxUser->password);
- fwrite (auxUser, sizeof(struct user), 1, fp);
- clear();
- menu();
- break;
- }
- free (auxUser);
- fclose(fp);
- }
- /*
- PARTE DE EXPERIMENTAR A LISTA
- */
- locals_ptr Ler_Ficheiros(){
- locals_ptr L=NULL, aux;
- FILE *f;
- char buff[50];
- f=fopen("Locais.txt","r");
- if(f==NULL){
- printf("Erro ao abrir o ficheiro de Locais.\n");
- return(NULL);
- }
- while(fscanf (f, "%st", buff)!=EOF){
- if(L==NULL){
- L=(locals_ptr) malloc (1*sizeof(LOCALS));
- strcpy(L->name,buff);
- L->next=NULL;
- aux = L;
- }
- else {
- aux->next=(locals_ptr)malloc (1*sizeof(LOCALS));
- aux=aux->next;
- strcpy(aux->name,buff);
- aux->next=NULL;
- }
- }
- return (L);
- }
- void Showlist(LOCALS *L){
- if(L==NULL){
- printf("A Lista esta vazia!n");
- return;
- }
- else {
- while(L!=NULL){
- printf("%s\n",L->name);
- L=L->next;
- }
- }
- return;
- }
- locals_ptr create_locals_list(){
- locals_ptr aux;
- aux = (locals_ptr) malloc (sizeof(LOCALS));
- if (aux != NULL) {
- strcpy(aux->name,NULL);
- aux->local_pdi_ptr = NULL;
- aux->next = NULL;
- }
- return aux;
- }
- void insert_locals_list (locals_ptr ptr, char* n) {
- locals_ptr no;
- locals_ptr ant, inutil;
- no = (locals_ptr) malloc(sizeof(LOCALS));
- if (no != NULL) {
- strcpy(no->name, n) ;
- //procura_lista(ptr, n, &ant, &inutil);
- no->next = ant->next;
- ant->next = no;
- }
- }
- /*
- void procura_lista (locals_ptr lista, int chave, locals_ptr *ant, locals_ptr *actual) {
- *ant = lista;
- *actual = lista->next;
- while ((*actual) != NULL && (*actual)->num_aluno < chave) {
- *ant = *actual;
- *actual = (*actual)->next;
- }
- if ((*actual) != NULL && (*actual)->num_aluno != chave)
- *actual = NULL; // Se elemento não encontrado
- }
- */
- int main()
- {
- printf("OLAHAHS");
- user_ptr users_aux = create_users_list();
- userlogin(users_aux);
- locals_ptr locals_aux = create_locals_list();
- locals_aux = Ler_Ficheiros();
- /*
- LOCAIS *L=NULL;
- L=Ler_Ficheiros();
- Showlist(L);
- */
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement