1
I am not able to write data in binary in a file using the C language. Even using 'Wb' the output of the file are characters. How can I proceed? Here’s part of my code:
void cadastrar(void)
{
     if((fp=fopen("Jogos.dat", "wb"))==NULL)
     {
        printf("\nO arquivo nao pode ser aberto!\n");
        getch();
        exit(1);
     }
     fseek(fp,0L, SEEK_END);
 do
 {
    printf("\n Digite o Nome do Jogo ('FIM' para sair): ");
    gets(reg[quantidade_cadastro].nome_jogo);
    if ((strcmp(reg[quantidade_cadastro].nome_jogo,"fim")!=0)&&(strcmp(reg[quantidade_cadastro].nome_jogo,"FIM")!=0))
    {
        printf("\n Ano de Lancamento: ");
        scanf("%d",®[quantidade_cadastro].ano_lancamento);
        fflush(stdin);
        printf("\n Genero: ");
        gets(reg[quantidade_cadastro].genero);
        printf("\n Plataforma: ");
        gets(reg[quantidade_cadastro].plataforma);
        reg[0].status='1';
        if(fwrite(®, sizeof(struct registro), 1, fp) != 1)
        {
            printf("\nErro de Gravacao :/");
            getch();
        }
        else
        {
            quantidade_cadastro++;
            printf("\n Jogo Gravado no Arquivo!\n\n");
        }
    }
 }while((strcmp(reg[quantidade_cadastro].nome_jogo,"fim")!=0)&&(strcmp(reg[quantidade_cadastro].nome_jogo,"FIM")!=0));
 fclose(fp);}
						
What is the definition of
struct registro?– pmg
This is the record:
struct registro
{
 char nome_jogo[40];
 int ano_lancamento;
 char genero[20];
 char plataforma[20];
 char status;
 } reg[50];– Anderson