Advertisement
tutorfree

ED - leitura e gravação em arquivo binario

Jun 29th, 2016
422
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.57 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4.  
  5. typedef struct aluno
  6. {
  7.     int num;
  8.     char nome[10];
  9.     float nota;
  10. }Aluno;
  11.  
  12. int main()
  13. {
  14.     Aluno a,b;
  15.     a.num=100;
  16.     strcpy(a.nome, "Aluno");
  17.     a.nota=9.5;
  18.  
  19.     FILE *fp = fopen("saidaBin.bin","wb"); //gravação binario
  20.     fwrite(&a, sizeof(Aluno),1,fp);
  21.     fclose(fp);
  22.  
  23.     fp=fopen("saidaBin.bin","rb"); //leitura binário
  24.     fread(&b, sizeof(Aluno),1,fp);
  25.     printf("\nDados gravados:\nNum: %d, Nome: %s, Nota= %.1f\n\n",b.num,b.nome,b.nota);
  26.  
  27.     system("pause");
  28.     return 0;
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement