Created
May 23, 2012 19:09
-
-
Save alexsandro-xpt/2777148 to your computer and use it in GitHub Desktop.
Trabalhando com arquivos usando C++
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <stdlib.h> | |
#include <conio.h> | |
#include <string.h> | |
#include <iostream.h> | |
void main() { | |
FILE *arqF = fopen("c:\\funcionarios.txt","r"); | |
char nome[40]; | |
int chapa; | |
float salario; | |
if(arqF == NULL) { | |
printf("Não pude abrir o arquivo funcionarios.txt"); | |
getch(); | |
exit(1); | |
} | |
printf("Dados dos funcionarios\nChapa\tNome\tSalario\n"); | |
float salmaior=0, mediasalario=0; | |
int cont=0; | |
char nomemaior[40]; | |
while( ! feof(arqF) ) { | |
cont++; | |
fscanf(arqF, "%d%s%f", &chapa, nome, &salario); | |
if (salario>salmaior){ | |
salmaior=salario; | |
strcpy(nomemaior,nome); | |
//nomemaior=nome; | |
} | |
mediasalario=mediasalario+salario; | |
printf("%d\t%s\t%.2f\n", chapa, nome, salario); | |
} | |
mediasalario=mediasalario/cont; | |
cout<<salmaior<< " " <<mediasalario<< " "<<nomemaior; | |
fclose(arqF); | |
getch(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment