There are similar questions but my problem is a little more specific. I have a C code that takes file.txt and returns file.txt.rle when I am encoding by using RLE algorithm. Same way I decode that and want to write from file.txt.rle and return file.txt. The following code is what I am using as I go from file.txt to file.txt.rle:
char name[NAME_SIZE];
if(sprintf(name, "%s.rle", argv[1]) >= sizeof(name)){
fprintf(stderr, "Destination file name is too long\n");
}
while((o_fp = fopen(name, "wb")) == NULL){
fprintf(stderr, "Can't create the file to be written\n");
exit(1);
}
How can I accomplish to change the extension from file.txt.rle to file.txt when I decode? A full code won't help because I will use this in a code that decodes an encoded file.
Note: The given will always be in .txt.rle format and the returning file should always convert it to .txt.