Advertisement
joaoantoniodornelas

Prática 9 - Questão 1

Apr 29th, 2014
143
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.26 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <conio.h>
  4. #include <string.h>
  5. #include <ctype.h>
  6. #define MAX 80
  7.  
  8. char opcao_menu()
  9. {
  10. system("cls");
  11. printf(" (L)istar notas\n");
  12. printf(" (I)nserir aluno\n");
  13. printf(" (F)im\n");
  14. printf("> ");
  15. return (toupper(getche()));
  16. }
  17.  
  18. void listar_notas(){
  19.  
  20.     int num,notas;
  21.     float n1,n2,media;
  22.     char *nome;
  23.     char buf[MAX];
  24.     FILE *arq;
  25.     arq = fopen("dados.txt","r");
  26.     if (arq == NULL){
  27.         printf("Erro ao abrir arquivo\n");
  28.         return;
  29.     }
  30.     printf("\n");
  31.     printf("NUM | NOME | N1 | N2\n");
  32.     printf("----+----------------------+------+------\n");
  33.     notas = 0;
  34.     media = 0;
  35.     fgets(buf,MAX,arq);
  36.     while (!feof(arq))  {
  37.         num = atoi(strtok(buf,","));
  38.         nome = strtok(NULL,",");
  39.         n1 = atof(strtok(NULL,","));
  40.         n2 = atof(strtok(NULL,","));
  41.         printf("%03d | %-20s | %4.1f |%4.1f\n",num,nome,n1,n2);
  42.         notas = notas + 2;
  43.         media = media + n1 + n2;
  44.         fgets(buf,MAX,arq);
  45.     }
  46.  
  47.     printf("----+----------------------+------+------\n");
  48.     media = media/notas;
  49.     printf("Media das notas = %4.1f\n",media);
  50.     fclose(arq);
  51.  
  52. }
  53.  
  54. int main(int args, char * arg[]){
  55.     char op;
  56.  
  57.     do{
  58.         op = opcao_menu();
  59.         if (op == 'L'){
  60.             listar_notas();
  61.         }
  62.  
  63.         printf("\n");
  64.         system("pause");
  65.     }while (op !='F');
  66.  
  67.     return 0;
  68. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement