Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Updating a record in C

Status
Not open for further replies.

JamesPowell

Programmer
Aug 29, 2006
2
0
0
DE
Hi,

A simple problem, but I just can't get it to work...
I'm trying to read a record from a file, modify it and then write it back to file, updating the original record.

Can anyone tell me what I'm doing wrong.
I'm doing something like this.

void main (int argc, char *argv[])
{
char rec[3];

FILE *fp = fopen("a.dat", "r+");
int bytes = fread(rec, 1, sizeof(rec), fp);
rec[0] = 'V';
bytes = fwrite(rec, 1, sizeof(rec), fp);

fclose(fp);
}

Thanks

James
 
I think you need to rewind your file pointer back to the beginning of the file before you write.

fseek would be the function to use for this.

Carl




 
No its not a binary file.
But, its fixed now anyway.
carlg was correct when he said to use the fseek() function.

Thanks anyway
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top