Have a look at this version, it should do what you want.
Code:
int delete_record(void)
{
FILE *dta_file, *temp_file;
struct fclient another_client;
int client_code;
/*
* Read the users input (client code)
*/
if (scanf("%d",&client_code) != 1)
{
printf ("That was not a number!\n");
return (1);
}
/*
* Open the two files
*/
if((dta_file=fopen(FILENAME,"rb")) == NULL)
{
perror(FILENAME);
return(1);
}
if((temp_file=fopen(FILENAME2,"wb")) == NULL)
{
perror(FILENAME);
return(1);
}
/*
* Read the IN file, comparing each structs client_code with
* that which the user entered. If match found, we don't write
* out, if no match we do write out.
*/
while((fread(&another_client,sizeof(struct fclient),1,dta_file)) == 1)
{
if(client_code == another_client.client_code)
{
printf("\n\nThe client has been deleted from the inventory...");
}
else
{
if((fwrite(&another_client,sizeof(struct fclient),1,temp_file)) != 1)
{
perror("write");
fclose(dta_file);
fclose(temp_file);
return(1);
}
}
}
/*
* Close the two files
*/
fclose(dta_file);
fclose(temp_file);
/*
* Remove the existing file, and rename the temporary one in it's place
*/
remove(FILENAME);
if (rename(FILENAME2, FILENAME) != 0) perror("rename");
key_wait();
return (0);
}
I shouldn't really be writing a complete function for you, but I've been running out of ways to explain things
Notice the functions return type has changed, there was no point in returning a char.
Read through this code, and make sure you understand it properly before trying to use it.