Ficheiros em C

Boas.
Tenho esta seguinte estrutura:
typedef struct Quiz{
char nickname[7];
char nome[50];
int pontuacao;
}PARTICIPANTE;
Como é que eu faço para inserir um novo participante num ficheiro e verificar se esse participante já exite neste ficheiro,caso ele existe nao pode ser acrescentado ao ficheiro.
Obrigado
Fiz isto ate agora:





void InsereParticipante(char*nomeF){
PARTICIPANTE aux, participante,p;
FILE *f;
int existe=0;
aux=leParticipante();
f=fopen(nomeF, "rb+");
if(f==NULL){
printf("ERRO");
getch();
exit(1);
}
while(fread(&participante,sizeof(PARTICIPANTE),1,f)!=0){
if(aux.nickname==p.nickname){
existe=1;
printf("já existe");
getch();
break;
}
}
if(existe==0)
fwrite(&aux,sizeof(PARTICIPANTE),1,f);
printf("Participante inserido com sucesso!");
getch();

fclose(f);
}
 
Boas,
Não olhei a fundo o teu programa mas parece-me que isto:
Código:
if(aux.nickname==p.nickname){
não vai funcionar. Usa o strcmp:
Código:
if( strcmp(aux.nickname,p.nickname)==0 ){

PS: Não te esqueças que nickname tem que terminar em '\0' para ser string
 
Back
Topo