Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include "estruturas.h"
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- /*
- LOGIN E REGISTO
- */
- void userlogin(void){
- USERS *auxUser=NULL;
- FILE *fp;
- char uName[10];
- char pWord[10];
- int i;
- auxUser=(USERS*) malloc (1*sizeof(USERS));
- printf("1. Login \n");
- printf("2. Registar\n");
- scanf("%d",&i);
- switch(i){
- case 1:
- if ( ( fp=fopen("user.dat", "r+")) == NULL) {
- if ( ( fp=fopen("user.dat", "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");
- /*
- ABRIR MENU DEPOIS
- accessUser();
- */
- }else{
- printf("dados incorretos\n");
- }
- }
- }
- break;
- case 2:
- if ( ( fp=fopen("user.dat", "a+")) == NULL) {
- if ( ( fp=fopen("user.dat", "w+")) == NULL) {
- printf ("ERRO AO ABRIR O FICHEIRO\n");
- exit ( 1);
- }
- }
- printf("Choose A Username: ");
- scanf("%9s",auxUser->username);
- printf("Choose A Password: ");
- scanf("%9s",auxUser->password);
- fwrite (auxUser, sizeof(struct user), 1, fp);
- break;
- }
- free (auxUser);
- fclose(fp);
- }
- /*
- PARTE DE EXPERIMENTAR A LISTA
- */
- locals_ptr Ler_Ficheiros(){
- locals_ptr L = NULL;
- FILE *f;
- char buff[MAX];
- f=fopen("Locais.txt","r");
- if(f==NULL){
- printf("Erro ao abrir o ficheiro de Locais\n");
- return(NULL);
- }
- while(fgets(f, "%s", buff)!=EOF){
- L = create_locals_list();
- strcpy(L->name,buff);
- }
- return L;
- }
- void Showlist(locals_ptr L){
- if(L==NULL){
- printf("A Lista esta vazia!\n");
- return;
- }
- else {
- while(L!=NULL){
- printf("%s\n",L->name);
- L=L->next;
- }
- }
- }
- 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;
- }
- int main() {
- locals_ptr L = NULL;
- L = Ler_Ficheiros();
- Showlist(L);
- printf("aloha\n");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement