Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <string.h>
- #include <stdio.h>
- struct aluno {
- char nome[50];
- int numero;
- int nota;
- };
- struct aluno alunos[50];
- int posicao=0;
- void adiciona_aluno(struct aluno temp){
- alunos[posicao]=temp;
- posicao++;
- }
- void processa_notas (FILE *ficheiro, struct aluno[], int sz){
- char nometemp[30];
- int numtemp;
- int notatemp;
- int i=0;
- sz =50;
- while(fscanf(ficheiro, "%s %d %d", nometemp, &numtemp, ¬atemp) !=EOF){
- struct aluno alunotemp;
- strcpy(alunotemp.nome, nometemp);
- alunotemp.numero = numtemp;
- alunotemp.nota = notatemp;
- adiciona_aluno(alunotemp);
- i++;
- }
- }
- struct aluno maior_nota(struct aluno alunos[], int sz){
- int nota=-1;
- int pos_mais_alta= -1;
- int i=0;
- sz=50;
- while (i<posicao){
- if(alunos[i].nota > nota){
- nota = alunos[i].nota;
- pos_mais_alta = i;
- }
- i++;
- }
- return alunos[pos_mais_alta];
- }
- void printstruct(FILE*ficheiro, struct aluno temp){
- fprintf(ficheiro, "%d = %d\n", temp.numero, temp.nota);
- }
- void escreve_notas(char nome_in[], char nome_out[]){
- int i=0;
- while(i<posicao){
- printstruct(ficheiro, alunos[i]);
- i++;
- }
- int conta_alunos(FILE* ficheiro){
- char c[100];
- int alunos=0;
- while ((fscanf(ficheiro, "%s", c)) !=EOF){
- alunos++;
- }
- return alunos;
- }
- int main()
- {
- FILE* ficheiro;
- int alunos;
- ficheiro = fopen("notas.txt", "r");
- alunos = conta_alunos(ficheiro);
- printf("O numero de alunos é: %d", alunos);
- fprintf(ficheiro, "# prova de %d alunos\n", posicao);
- fprintf(ficheiro, "#a nota mais alta: %s, %d, %d\n", temp.nome, tempnumero, temp.nota);
- escreve_notas(nome_in[], nome out[]);
- printArr(ficheiro);
- temp = maior_nota(aluno alunos[], sz);
- processa_notas (ficheiro, aluno[], sz);
- fclose(ficheiro);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement