I have a file name "test.mf" as a character pointer. I want to change extension of this file into "test.pfb". I am writing a simple code for this but it is resulting in printing some garbage characters. Running same code on online C compiler results in no garbage values but running it using GCC results in garbage value. If I can achieve the same thing (changing file extension of .mf file to .pfb) in a much better, fast way please suggest. I am new in this so please ignore silly mistakes.
Code
char *Get_PFB_font_file_name(char *TTF_Font_name)
{
size_t alen = strlen(TTF_Font_name);
alen = alen+1;
char mystring[alen];
const char* extension = ".pfb";
char *PFB_File= malloc(alen+1);
strncpy(mystring, TTF_Font_name, alen-4);
strcat( mystring, extension );
strncpy(PFB_File, mystring, alen);
if(!PFB_File)
{
printf("error in get TTX conversion function");
exit(1);
}
return PFB_File;
}
int main ( void )
{
char *MF_Font_file_name = "test.mf";
char *PFB_Font_file_name;
PFB_Font_file_name = Get_PFB_font_file_name(MF_Font_file_name);
printf("PFB font file name is %s \n", PFB_Font_file_name); // garbage value here (test�.p)
return 0;
}