0

我试图通过搜索名称来查找二进制文件中是否存在记录。
似乎我没有做正确的事情,因为我的“如果”返回,无论输入如何,它总是在它不存在时被发现。
调试器状态“如果 = 表达式中的语法错误”,我没有看到它。

#ifndef DATA_PLAYER_H_INCLUDED
#define DATA_PLAYER_H_INCLUDED
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

typedef struct Player
{
    char nome[50];
    int pontos;
}Players;

void ViewPont();
void SearchPont();
#endif // DATA_PLAYER_H_INCLUDED

--

#include "DATA_PLAYER.h"

void ViewPont()
{
    Players pl;
    FILE *fp;
    int i, pontos;

    fp = fopen("Pontuacoes.dat", "rb+");

        while((fread(&pl, sizeof(Players),1, fp)) != 0 )
    {
        printf("%s %d\n", pl.nome, pl.pontos);
    }

    fclose(fp);
}

void SearchPont()
{
    char nam[50];
    char ch;
    Players pl;
    FILE * fp;

    fp = fopen("Pontuacoes.dat","rb+");

    printf("\n nome das pont\n");
    fflush(stdout);
    scanf("%s", nam);

    printf("%s", nam);

    while((fread(&pl, sizeof(Players),1, fp)) != 0)
    {
        if((strcmp(pl.nome, nam))==0);
        {
            printf("\nregisto encontrado\n");
        }

    }
fclose(fp);

}
4

1 回答 1

1

傻我…………

if(strcmp(pl.nome, nam) ==0);

->; 那个小细节……

if(strcmp(pl.nome, nam) ==0)
于 2012-06-10T01:37:31.550 回答