-1
Hey there, guys! I’m making a code for the records of patients who tested positive for COVID. When the patient is registered, their data is sent to a txt file. The problem occurs when a patient is over 65 years old and must have their data recorded in another file separate from other patients. At the moment of checking the age and recording the data in another file, I have problems at the time of recording. I can’t get it recorded in the file I want. I’m a beginner in C and I’d like your help.
From the use of if it is possible to create another file to put the data of the patient who is over 65 years?
void inputPaciente(){
PACIENTE pct;
FILE* arquivo;
arquivo = fopen("lista_pacientes.txt", "ab");
if(arquivo == NULL){
printf("Problemas na abertura do arquivo.");
}
else{
do{
cabecalho();
printf("\nINSIRA OS DADOS DO PACIENTE\n");
fflush(stdin);
printf("\nNome: ");
scanf("%[^\n]s", pct.nome);
fflush(stdin);
printf("\nCPF: ");
scanf("%[^\n]s", pct.CPF);
fflush(stdin);
printf("\nTelefone: ");
scanf("%[^\n]s", pct.telefone);
fflush(stdin);
printf("\nEndereço completo: ");
scanf("%[^\n]s", pct.endereco);
fflush(stdin);
printf("\nCEP: ");
scanf("%[^\n]s", pct.CEP);
fflush(stdin);
printf("\nData De nascimento (DD/MM/AAAA): ");
scanf("%d %d %d", &pct.aniv.dia, &pct.aniv.mes, &pct.aniv.ano);
fflush(stdin);
printf("\nDigite o email do paciente: ");
scanf("%[^\n]s", pct.email);
fflush(stdin);
printf("\nData do diagnostico (DD/MM/AAAA): ");
scanf("%s", pct.dataDoDiagnostico);
fflush(stdin);
printf("\nO paciente possui alguma comorbidade?: ");
scanf("%[^\n]s", pct.comorbidade);
fwrite(&pct, sizeof(PACIENTE), 1, arquivo);
printf("\nDeseja continuar (s/n)?");
}while(getche() == 's');
fclose(arquivo);
}
}
If you want to write to another file then you need to have another file (declare, open, write and close), your routine works with a single file.
– anonimo
The problem is I don’t know how and at what point in the code I should do this.
– Lady Pavlichenko
Where you have a reference to
arquivo
do the same thing with, for example,arquivo65
. Treat yourdataDoDiagnostico
not as a string but as composed of the day, month and year fields. Before recording check if the date of birth is <= date of diagnosis - 65 years and record either on file or in archive65.– anonimo
I don’t think you should record it in another file, it should be a property of the "Patient" object. And I can’t understand what’s in your doubt...
– Leandro Angelo
Now I understand what must be done. Thank you, people!!!
– Lady Pavlichenko