void update(char * record1,char *record2,char *record3)
{
system("color 2");
int tell=0;
int Found=0;
long int offset = -1;
char treat[30];
char app[30];
if((customer1=fopen("customer1.txt","r+"))==NULL)
printf("THE FILE IS EMPTY");
else
{
while(fscanf(customer1,"%s %s %s %s %s %s %s %s",info.regis,info.Name,info.address,info.number,info.dob,info.treatment,info.allergies,info.app)==8
&& Found==0)
{
offset = ftell(customer1);
//fscanf(customer1,"%s %s %s %s %s %s %s %s\n",info.regis,info.Name,info.address,info.number,info.dob,info.treatment,info.allergies,info.app);
if(strcmp(record1,info.regis)==0)
Found=1;
}
if(Found)
{
strcpy(treat,record2);
strcpy(app,record3);
fseek(customer1,offset,SEEK_SET);
fprintf(customer1,"%s %s %s %s %s %s %s %s ",info.regis,info.Name,info.address,info.number,info.dob,treat,info.allergies,app);
// printf("\n\n\t\t THE DETAILS OF THE ITEM HAS BEEN UPDATED SUCCESSFULLY");
rewind(customer1);
}
else
if(!Found)
printf("\n\n\t\t THERES NO SUCH RECORD");
}
fclose(customer1);
}
Not overwriting
Started by hbk, Mar 13 2010 06:03 PM
1 reply to this topic
#1
Posted 13 March 2010 - 06:03 PM
I am passing three char parameter to a function below with a desired input but when i can scan the data from the file and then reprinting to the file with the updated data its not carrying out the diserd output to the file. instead it prints back the information at the end of the record.
|
|
|
#2
Posted 13 March 2010 - 11:27 PM
Thats because you call fseek(customer1, offset, SEEK_SET) while your offset is initiated by ftell after having scanned the whole file. So after the last loop iteration, offset will indicate the end of the data in file.


Sign In
Create Account


Back to top









