I require to add a string before 45byte in an existing file. I tried using fseek as bellow.
int main()
{
FILE *fp;
char str[] = "test";
fp = fopen(FILEPATH,"a");
fseek(fp,-45, SEEK_END);
fprintf(fp,"%s",str);
fclose(fp);
return(0);
}
I expected that this code will add "test" in before 45 char from EOF. But it just appends "test" to the EOF.
Please help me to find the solution.
This is continuation of my previous question
http://stackoverflow.com/questions/3262886/append-item-to-a-file-before-last-line-in-c