Look my search function which is working fine.
Code:
void SO_searchRecord(FILE *IO)
{
int recsNum;
char id[9];
char toCmp[recSize];
record tempRec;
//Initilize
recsNum = 0;
rewind(IO);
memset(toCmp,0,recSize);
//Interface
printf("\nInsert the ID of the record to search for : ");
getStr(id,9);
while(checkStr(id,ALN))
{
printf("ID should be consisted of letters and numbers.\n");
printf("Insert ID : ");
getStr(id,9);
}
printf("\nRecord(s) found with ID %s : ",id);
//Start to search
while(fread(&tempRec,1,recSize,IO) == recSize)
{
if((memcmp(&tempRec,toCmp,recSize) != 0)&&(strcmp(tempRec.id,id) == 0))
{
puts("\n");
fprintf(stdout,"-------%d-------\n",++recsNum);
fprintf(stdout,"ID : %s \n",tempRec.id);
fprintf(stdout,"Surname : %s \n",tempRec.surname);
fprintf(stdout,"Name : %s \n",tempRec.name);
fprintf(stdout,"Origin : %s \n",tempRec.origin);
fprintf(stdout,"Salary : %d \n",tempRec.salary);
}
}
//If no record found
if(recsNum == 0)
puts("None\n");
}
It's working the same way !!!!