Skip to content

Instantly share code, notes, and snippets.

@rauldeavila
Created May 25, 2018 13:40
Show Gist options
  • Save rauldeavila/e1203f256210274ac0649eaa6502af3c to your computer and use it in GitHub Desktop.
Save rauldeavila/e1203f256210274ac0649eaa6502af3c to your computer and use it in GitHub Desktop.
fopen
#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