Saturday, December 14, 2019

filename up to the extension and creating a new filename

Just dropping this here for now.

void getFilenameWithNoExtensionAndCreateANewFilename()
{
char *arg= (char *)"foobar_filename.ppm";
char output_filename[256];

char* ptrToPPMStart = NULL;
char* ptrCopyFrom = NULL;

char buf[80] = { 0 };
int i = 0;

ptrCopyFrom = arg;
ptrToPPMStart = strrchr(arg, '.');

while (ptrCopyFrom != ptrToPPMStart) 
{
// printf("copying %c\n", *ptrCopyFrom);
buf[i] = *ptrCopyFrom;
i++;
ptrCopyFrom++;

}

buf[i] = '\0';

printf("%s\n", buf);


strcpy_s(output_filename, "output_");

//from this create a new filename
strcat_s(output_filename, arg);

printf("output_filename: %s\n", output_filename);
}

No comments: