Created
May 25, 2018 13:40
-
-
Save rauldeavila/e1203f256210274ac0649eaa6502af3c to your computer and use it in GitHub Desktop.
fopen
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 <string.h> | |
#define MAXSCORES 99999 | |
typedef struct | |
{ | |
char nome[40]; | |
int score; | |
} TIPO_SCORE; | |
int main() { | |
FILE *arquivo; | |
arquivo = fopen("binario_g.bin", "rb+"); | |
int quantidade = 0; | |
if (arquivo == NULL){ // abre o arquivo e testa. Erro devolve -1. | |
printf("\n\n-1\n\n"); | |
} else { | |
while(!feof(arquivo)){ // Enquanto o cursor nao chegou ao fim do arquivo... | |
fread(&quantidade, 1, MAXSCORES, arquivo); | |
} | |
printf("O numero de entradas lidas eh: %d", quantidade); | |
} | |
fclose(arquivo); // fechando o arquivo apos o uso | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment