Advertisement
Guest User

Untitled

a guest
Jun 17th, 2019
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.22 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <time.h>
  4. #include <iostream>
  5. #include <string>
  6.  
  7.  
  8. typedef struct{
  9. int cod;
  10. char nome[60];
  11. char end[300];
  12. int fone[8];
  13. }medico;
  14. typedef struct{
  15. int codC;
  16. int codM;
  17. int codP;
  18. int diaS;
  19. char hora[6];
  20. }consulta;
  21. typedef struct{
  22. int cod;
  23. char nome[60];
  24. char end[300];
  25. int fone[8];
  26. }pacientes;
  27.  
  28. void config(int *a, int *b, int *c){
  29. FILE *p;
  30. if((p = fopen("config.txt","r"))==NULL){
  31. printf("Erro na abertura do arquivo config");
  32. system("pause");
  33. exit(1);
  34. }
  35. fscanf(p,"%d",&(*a));
  36. fscanf(p,"%d",&(*B));
  37. fscanf(p,"%d",&(*c));
  38. }
  39. void dia(char *arquivo){
  40. char d[2],m[2],a[4];
  41. int s, temp;
  42. time_t tempo;
  43. struct tm *data;
  44. time(&tempo); /* 'tempo' fica com a marca deste instante. */
  45. data = localtime(&tempo);
  46. fflush(stdin);//Limpa o buffer
  47. s=((*data).tm_wday); //dia da semana de 0 a 6
  48. itoa((*data).tm_year+1900, a, 10);
  49. strcpy(arquivo, a);
  50. itoa((*data).tm_mon+1, m, 10);
  51. strcat(arquivo, m);
  52. temp = (*data).tm_mday; // tratar
  53. s==0 ? temp=temp+1 : 0; // nome do
  54. s>1 ? temp=temp-(s-1) : 0; // arquivo
  55. itoa(temp, d, 10);
  56. strcat(arquivo, d);
  57. strcat(arquivo, ".txt");
  58. }
  59. void cadMed(int *Nmed){
  60. fflush(stdin);//Limpa o buffer
  61. FILE *p;
  62. if((p = fopen("medicos.txt","a+"))==NULL)
  63. printf("erro na abertura de 'medicos.txt'");
  64. fprintf(p, "%dn",*Nmed+1);
  65. char arquivo[60], nome[200], end[300], tel[8];
  66. printf("Digite o nome do medico:");
  67. fflush(stdin); fgets(nome, 200, stdin);
  68. fprintf(p, "%s", strupr(nome));
  69. printf("Digite o endereco do medico:");
  70. fflush(stdin); fgets(end, 300, stdin);
  71. fprintf(p, "%s",strupr(end));
  72. printf("Digite o telefone do medico:");
  73. fflush(stdin); fgets(tel, 9, stdin);
  74. fprintf(p, "%s",strupr(tel));
  75. *Nmed = *Nmed+1;
  76. }
  77. void cadPac(int *Codpac)
  78. {
  79. char nome[100], end[300], tel[8];
  80. fflush (stdin);
  81. FILE *arq;
  82. if((arq = fopen("pacientes.txt","a+"))==NULL)
  83. printf("Erro ao abrir 'pacientes.txt'n ");
  84. fprintf(arq, "%dn",*Codpac+1);
  85. printf("Digite o nome do paciente:");
  86. fflush(stdin); fgets(nome,300,stdin);
  87. fprintf(arq, "%s",strupr(nome));
  88. printf("Digite o endereco do paciente:");
  89. fflush(stdin); fgets(end, 300, stdin);
  90. fprintf(arq, "%s",strupr(end));
  91. printf("Digite o telefone do paciente:");
  92. fflush(stdin); fgets(tel, 9, stdin);
  93. fprintf(arq, "%s",strupr(tel));
  94. *Codpac = *Codpac+1;
  95. }
  96. //imprime o menu e retorna a opcao escolhida pelo usuario
  97. int escolherMenu()
  98. {
  99. int resp, e=0;
  100. do{
  101. system("cls");
  102. e == 1 ? printf("Opcao invalida! Tente novamente!n") : 0;
  103. puts("Escolha sua opcao:");
  104. puts(" 1 - Cadastrar Medico.");
  105. puts(" 2 - Cadastrar Paciente.");
  106. puts(" 3 - Sair.");
  107. fflush(stdin);
  108. scanf("%d", &resp);
  109. switch(resp){
  110. case 1: case 2:
  111. return resp;
  112. case 3:
  113. exit(1);
  114. default:
  115. e = 1;
  116. }
  117. }while(e==1);
  118. }
  119. int qtdLinhas(FILE *arq) //Conta marcas de 'fim_de_linha' do arquivo de caracteres
  120. {
  121. int n = 0;
  122. char c;
  123. rewind(arq);
  124. while((c=getc(arq))!=EOF) if(c=='n')n++;
  125. rewind(arq);
  126. return n;
  127. }
  128. void AceConsulta(char *arquivo, int m, int d)
  129. {
  130. FILE *p;
  131. int l;
  132. consulta con;
  133. if((p = fopen(arquivo,"r+"))==NULL)
  134. printf("Erro ao abrir os arquivos de consultas");
  135. l = qtdLinhas(p);
  136. printf("passoi1");
  137. for(int j=0, m=2;j<(l+1)/5;j++)
  138. {
  139. fscanf(p,"%d",con.codC);
  140. printf("Consulta numero %d:n",j);
  141. fscanf(p,"%d",con.codM);
  142. fscanf(p,"%d",con.codP);
  143. fscanf(p,"%d",con.diaS);
  144. fscanf(p,"%s",con.hora);
  145. if(con.codM == m && con.diaS == d){
  146. printf("Consulta numero %d:n",j);
  147. printf("Codigo do Paciente %d:n",con.codP);
  148. printf("Hora: %s:n",con.hora);
  149. }
  150. }
  151. fclose(p);
  152. }
  153.  
  154.  
  155.  
  156. main()
  157. {
  158. // Retorna o numero de medicos|pacientes|consultas na semana
  159. int Nmed, Npac, Ncon;
  160. config(&Nmed, &Npac, &Ncon);
  161.  
  162. char arquivo[12];
  163. dia(arquivo);
  164. printf("%s", arquivo);
  165.  
  166. int m=2, d=1;
  167. AceConsulta(arquivo, 2, 1);
  168. system("pause");
  169.  
  170.  
  171. /*cadPac(&Npac);
  172. cadMed(&Nmed);*/
  173. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement