Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <time.h>
- #include <iostream>
- #include <string>
- typedef struct{
- int cod;
- char nome[60];
- char end[300];
- int fone[8];
- }medico;
- typedef struct{
- int codC;
- int codM;
- int codP;
- int diaS;
- char hora[6];
- }consulta;
- typedef struct{
- int cod;
- char nome[60];
- char end[300];
- int fone[8];
- }pacientes;
- void config(int *a, int *b, int *c){
- FILE *p;
- if((p = fopen("config.txt","r"))==NULL){
- printf("Erro na abertura do arquivo config");
- system("pause");
- exit(1);
- }
- fscanf(p,"%d",&(*a));
- fscanf(p,"%d",&(*B));
- fscanf(p,"%d",&(*c));
- }
- void dia(char *arquivo){
- char d[2],m[2],a[4];
- int s, temp;
- time_t tempo;
- struct tm *data;
- time(&tempo); /* 'tempo' fica com a marca deste instante. */
- data = localtime(&tempo);
- fflush(stdin);//Limpa o buffer
- s=((*data).tm_wday); //dia da semana de 0 a 6
- itoa((*data).tm_year+1900, a, 10);
- strcpy(arquivo, a);
- itoa((*data).tm_mon+1, m, 10);
- strcat(arquivo, m);
- temp = (*data).tm_mday; // tratar
- s==0 ? temp=temp+1 : 0; // nome do
- s>1 ? temp=temp-(s-1) : 0; // arquivo
- itoa(temp, d, 10);
- strcat(arquivo, d);
- strcat(arquivo, ".txt");
- }
- void cadMed(int *Nmed){
- fflush(stdin);//Limpa o buffer
- FILE *p;
- if((p = fopen("medicos.txt","a+"))==NULL)
- printf("erro na abertura de 'medicos.txt'");
- fprintf(p, "%dn",*Nmed+1);
- char arquivo[60], nome[200], end[300], tel[8];
- printf("Digite o nome do medico:");
- fflush(stdin); fgets(nome, 200, stdin);
- fprintf(p, "%s", strupr(nome));
- printf("Digite o endereco do medico:");
- fflush(stdin); fgets(end, 300, stdin);
- fprintf(p, "%s",strupr(end));
- printf("Digite o telefone do medico:");
- fflush(stdin); fgets(tel, 9, stdin);
- fprintf(p, "%s",strupr(tel));
- *Nmed = *Nmed+1;
- }
- void cadPac(int *Codpac)
- {
- char nome[100], end[300], tel[8];
- fflush (stdin);
- FILE *arq;
- if((arq = fopen("pacientes.txt","a+"))==NULL)
- printf("Erro ao abrir 'pacientes.txt'n ");
- fprintf(arq, "%dn",*Codpac+1);
- printf("Digite o nome do paciente:");
- fflush(stdin); fgets(nome,300,stdin);
- fprintf(arq, "%s",strupr(nome));
- printf("Digite o endereco do paciente:");
- fflush(stdin); fgets(end, 300, stdin);
- fprintf(arq, "%s",strupr(end));
- printf("Digite o telefone do paciente:");
- fflush(stdin); fgets(tel, 9, stdin);
- fprintf(arq, "%s",strupr(tel));
- *Codpac = *Codpac+1;
- }
- //imprime o menu e retorna a opcao escolhida pelo usuario
- int escolherMenu()
- {
- int resp, e=0;
- do{
- system("cls");
- e == 1 ? printf("Opcao invalida! Tente novamente!n") : 0;
- puts("Escolha sua opcao:");
- puts(" 1 - Cadastrar Medico.");
- puts(" 2 - Cadastrar Paciente.");
- puts(" 3 - Sair.");
- fflush(stdin);
- scanf("%d", &resp);
- switch(resp){
- case 1: case 2:
- return resp;
- case 3:
- exit(1);
- default:
- e = 1;
- }
- }while(e==1);
- }
- int qtdLinhas(FILE *arq) //Conta marcas de 'fim_de_linha' do arquivo de caracteres
- {
- int n = 0;
- char c;
- rewind(arq);
- while((c=getc(arq))!=EOF) if(c=='n')n++;
- rewind(arq);
- return n;
- }
- void AceConsulta(char *arquivo, int m, int d)
- {
- FILE *p;
- int l;
- consulta con;
- if((p = fopen(arquivo,"r+"))==NULL)
- printf("Erro ao abrir os arquivos de consultas");
- l = qtdLinhas(p);
- printf("passoi1");
- for(int j=0, m=2;j<(l+1)/5;j++)
- {
- fscanf(p,"%d",con.codC);
- printf("Consulta numero %d:n",j);
- fscanf(p,"%d",con.codM);
- fscanf(p,"%d",con.codP);
- fscanf(p,"%d",con.diaS);
- fscanf(p,"%s",con.hora);
- if(con.codM == m && con.diaS == d){
- printf("Consulta numero %d:n",j);
- printf("Codigo do Paciente %d:n",con.codP);
- printf("Hora: %s:n",con.hora);
- }
- }
- fclose(p);
- }
- main()
- {
- // Retorna o numero de medicos|pacientes|consultas na semana
- int Nmed, Npac, Ncon;
- config(&Nmed, &Npac, &Ncon);
- char arquivo[12];
- dia(arquivo);
- printf("%s", arquivo);
- int m=2, d=1;
- AceConsulta(arquivo, 2, 1);
- system("pause");
- /*cadPac(&Npac);
- cadMed(&Nmed);*/
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement