Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <string.h>
- #include <math.h>
- struct TpPessoa
- {
- int Matricula;
- float Altura, Peso;
- char Sexo;
- };
- void GeraRelat(char NomeArq[100])
- {
- float IMC;
- char Situacao[50];
- TpPessoa P;
- FILE *PtrTxt = fopen(NomeArq, "r");
- if(PtrTxt != NULL)
- {
- FILE *PtrAux = fopen("IMC.txt", "a");
- fscanf(PtrTxt, "%d %f %f %c", &P.Matricula, &P.Altura, &P.Peso, &P.Sexo);
- while(!feof(PtrTxt))
- {
- IMC = P.Peso / pow(P.Altura, 2);
- if(P.Sexo == 'F')
- {
- if(IMC >= 24)
- strcpy(Situacao, "Acima");
- else if(IMC >= 19)
- strcpy(Situacao, "Ideal");
- else
- strcpy(Situacao, "Abaixo");
- }
- else
- {
- if(IMC >= 24)
- strcpy(Situacao, "Acima");
- else if(IMC >= 19)
- strcpy(Situacao, "Ideal");
- else
- strcpy(Situacao, "Abaixo");
- }
- fprintf(PtrAux, "%d %.2f %s\n", P.Matricula, IMC, Situacao);
- fscanf(PtrTxt, "%d %f %f %c", &P.Matricula, &P.Altura, &P.Peso, &P.Sexo);
- }
- fclose(PtrTxt);
- fclose(PtrAux);
- }
- }
- int main(void)
- {
- GeraRelat("d.txt");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement