我試圖通過搜索名稱來查找二進制文件中是否存在記錄。
似乎我沒有做正確的事情,因爲我的「if」的返回無論它總是在不存在的時候發現它的輸入。
調試器指出「if =表達式中的語法錯誤」,我沒有看到它。在二進制文件上搜索記錄
#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);
}
如果你重寫這樣的錯誤,錯誤會消失嗎? 'if(strcmp(pl.nome,nam)== 0)'? – sarnold
不,調試器仍然表示相同 – CMCB