Advertisement
Guest User

Untitled

a guest
Dec 12th, 2019
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.83 KB | None | 0 0
  1. #include <string.h>
  2. #include <stdio.h>
  3.  
  4.  
  5.  
  6. struct aluno {
  7. char nome[50];
  8. int numero;
  9. int nota;
  10. };
  11.  
  12. struct aluno alunos[50];
  13. int posicao=0;
  14.  
  15. void adiciona_aluno(struct aluno temp){
  16. alunos[posicao]=temp;
  17. posicao++;
  18. }
  19.  
  20.  
  21. void processa_notas (FILE *ficheiro, struct aluno[], int sz){
  22.  
  23. char nometemp[30];
  24. int numtemp;
  25. int notatemp;
  26. int i=0;
  27. sz =50;
  28. while(fscanf(ficheiro, "%s %d %d", nometemp, &numtemp, &notatemp) !=EOF){
  29. struct aluno alunotemp;
  30. strcpy(alunotemp.nome, nometemp);
  31. alunotemp.numero = numtemp;
  32. alunotemp.nota = notatemp;
  33.  
  34. adiciona_aluno(alunotemp);
  35. i++;
  36. }
  37.  
  38. }
  39.  
  40.  
  41. struct aluno maior_nota(struct aluno alunos[], int sz){
  42. int nota=-1;
  43. int pos_mais_alta= -1;
  44. int i=0;
  45. sz=50;
  46. while (i<posicao){
  47. if(alunos[i].nota > nota){
  48. nota = alunos[i].nota;
  49. pos_mais_alta = i;
  50. }
  51. i++;
  52. }
  53. return alunos[pos_mais_alta];
  54. }
  55.  
  56. void printstruct(FILE*ficheiro, struct aluno temp){
  57. fprintf(ficheiro, "%d = %d\n", temp.numero, temp.nota);
  58. }
  59.  
  60.  
  61.  
  62. void escreve_notas(char nome_in[], char nome_out[]){
  63. int i=0;
  64. while(i<posicao){
  65. printstruct(ficheiro, alunos[i]);
  66. i++;
  67. }
  68.  
  69.  
  70.  
  71. int conta_alunos(FILE* ficheiro){
  72.  
  73. char c[100];
  74. int alunos=0;
  75. while ((fscanf(ficheiro, "%s", c)) !=EOF){
  76. alunos++;
  77. }
  78.  
  79. return alunos;
  80. }
  81.  
  82.  
  83. int main()
  84. {
  85. FILE* ficheiro;
  86. int alunos;
  87. ficheiro = fopen("notas.txt", "r");
  88. alunos = conta_alunos(ficheiro);
  89. printf("O numero de alunos é: %d", alunos);
  90.  
  91. fprintf(ficheiro, "# prova de %d alunos\n", posicao);
  92. fprintf(ficheiro, "#a nota mais alta: %s, %d, %d\n", temp.nome, tempnumero, temp.nota);
  93. escreve_notas(nome_in[], nome out[]);
  94. printArr(ficheiro);
  95. temp = maior_nota(aluno alunos[], sz);
  96. processa_notas (ficheiro, aluno[], sz);
  97. fclose(ficheiro);
  98.  
  99. return 0;
  100. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement