For some reason, when I call fwrite(), it doesn't overwrite the file pointed to by the pointer. When I run the program, it displays that the tag of the file was replaced by the inputted tag specified by the user. After I check the file using a separate code to see the current tags, the tag wasn't replaced at all. I believe there is something wrong with how I used fwrite and into thinking that it would really overwrite the file. The tag in this case is the title. Here is the code:
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include "title.h"
char title[30];
char title1[30];
int main(int argc, char *argv[]){
FILE *fPtrs;
// print the current tag
fPtrs = fopen(argv[1],"r+b");
fseek(fPtrs,-125,SEEK_END);
fread(title1,1,30,fPtrs);
strncpy(title,title1,30);
printf("%s\n",title);
fclose(fPtrs);
// call to overwrite the current tag
fPtrs = fopen(argv[1],"w+b");
title_tag(fPtrs,argv[2]);
fclose(fPtrs);
// print the tag of the should be overwritten file
fPtrs = fopen(argv[1],"r+b");
fseek(fPtrs,-125,SEEK_END);
fread(title1,1,30,fPtrs);
strncpy(title,title1,30);
printf("%s\n",title);
fclose(fPtrs);
return 0;
}
#include<stdio.h>
void title_tag(FILE* fName, char title_s[]){
fseek(fName,-125,SEEK_END);
fwrite(title_s,1,30,fName);
}
This is a project I'm working on in the university and we were told that we were not allowed to use the id3lib -.-