Advertisement
Guest User

Untitled

a guest
May 14th, 2019
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.95 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include "estruturas.h"
  4.  
  5.  
  6.  
  7. #include <stdio.h>
  8. #include <stdlib.h>
  9. #include <string.h>
  10.  
  11. /*
  12. LOGIN E REGISTO
  13. */
  14.  
  15.  
  16.  
  17. void userlogin(void){
  18. USERS *auxUser=NULL;
  19. FILE *fp;
  20. char uName[10];
  21. char pWord[10];
  22. int i;
  23.  
  24. auxUser=(USERS*) malloc (1*sizeof(USERS));
  25.  
  26. printf("1. Login \n");
  27. printf("2. Registar\n");
  28. scanf("%d",&i);
  29.  
  30. switch(i){
  31. case 1:
  32. if ( ( fp=fopen("user.dat", "r+")) == NULL) {
  33. if ( ( fp=fopen("user.dat", "w+")) == NULL) {
  34. printf ("ERRO AO ABRIR O FICHEIRO\n");
  35. exit(1);
  36. }
  37. }
  38. printf("Username: ");
  39. scanf("%s",uName);
  40. printf("Password: ");
  41. scanf("%s",pWord);
  42. while ( fread (auxUser, sizeof(struct user), 1, fp) == 1) {
  43. if( strcmp ( auxUser->username, uName) == 0) {
  44. if( strcmp ( auxUser->password, pWord) == 0) {
  45. printf ("Dados Corretos. Login feito.\n");
  46. /*
  47. ABRIR MENU DEPOIS
  48. accessUser();
  49. */
  50. }else{
  51. printf("dados incorretos\n");
  52. }
  53. }
  54. }
  55. break;
  56.  
  57. case 2:
  58. if ( ( fp=fopen("user.dat", "a+")) == NULL) {
  59. if ( ( fp=fopen("user.dat", "w+")) == NULL) {
  60. printf ("ERRO AO ABRIR O FICHEIRO\n");
  61. exit ( 1);
  62. }
  63. }
  64. printf("Choose A Username: ");
  65. scanf("%9s",auxUser->username);
  66. printf("Choose A Password: ");
  67. scanf("%9s",auxUser->password);
  68. fwrite (auxUser, sizeof(struct user), 1, fp);
  69. break;
  70. }
  71. free (auxUser);
  72. fclose(fp);
  73. }
  74.  
  75.  
  76.  
  77. /*
  78. PARTE DE EXPERIMENTAR A LISTA
  79. */
  80.  
  81.  
  82.  
  83. locals_ptr Ler_Ficheiros(){
  84. locals_ptr L = NULL;
  85. FILE *f;
  86. char buff[MAX];
  87.  
  88. f=fopen("Locais.txt","r");
  89.  
  90. if(f==NULL){
  91. printf("Erro ao abrir o ficheiro de Locais\n");
  92. return(NULL);
  93. }
  94.  
  95. while(fgets(f, "%s", buff)!=EOF){
  96.  
  97.  
  98. L = create_locals_list();
  99. strcpy(L->name,buff);
  100. }
  101.  
  102. return L;
  103. }
  104.  
  105.  
  106.  
  107. void Showlist(locals_ptr L){
  108.  
  109. if(L==NULL){
  110. printf("A Lista esta vazia!\n");
  111. return;
  112. }
  113. else {
  114. while(L!=NULL){
  115. printf("%s\n",L->name);
  116. L=L->next;
  117. }
  118. }
  119. }
  120.  
  121.  
  122. locals_ptr create_locals_list(){
  123.  
  124.  
  125. locals_ptr aux;
  126. aux = (locals_ptr) malloc (sizeof (LOCALS));
  127. if (aux != NULL) {
  128. strcpy(aux->name,NULL);
  129. aux->local_pdi_ptr = NULL;
  130. aux->next = NULL;
  131. }
  132. return aux;
  133.  
  134. }
  135.  
  136. int main() {
  137.  
  138. locals_ptr L = NULL;
  139. L = Ler_Ficheiros();
  140. Showlist(L);
  141. printf("aloha\n");
  142. return 0;
  143. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement