Ze Diogo99
Membro
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);
}
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);
}