fseek - need some info please
I have read the boards, and It seems I am doing this right, but I am receiving garbage in my file:
I want to open a file, move to the 98th byte and write an email address:
Code:
define EMAILADDRLEN 90 // this is set above in the program
int e_loc = 98; // this is set above in the program
if ( (out = fopen("gorseve_10774.csv","w")) != NULL )
{
while ( (returnCode = fgets(lineOfText, LINESIZE, in )) != NULL)
{
e_loc = parseGorseveRecord(lineOfText);
printf("location found %d\n", e_loc);
if ( (ret = fseek(out, e_loc, SEEK_CUR)) == 0 )
{
fwrite("[email protected]",sizeof("[email protected]"),EMAILADDRLEN,out);
}
else
{
printf("Error locating write position\n");
exit(1);
}
fclose(out);
exit(0);
}
}
else
{
printf("Error Opening File: filename\n");
exit(1);
}