file_ext

Digital Signal Processing Library

Voice Lab

Program name: file_ext

Language: C

In file: file_lib.c

Objective: Create an output filename given: filename directory, filename basename, and filename extension.

Usage: void file_ext(char *out_name, char *directory, char *base_name, char *extension);

Parameters:

  • out_name - The name of the file to create
  • directory - The directory in which to create the output file
  • base_name - file basename.
  • extension - The extension of the out file name, to add to the base name.
Return:
  • Null

Mathematical Description:

Comments: Routine used to create out_name from directory name, basename and extension

User Comments

Code:

void file_ext(char *out_name, char *directory, char *base_name, char *extension)
{
        int i, j;
        int upper_case;
        char buffer[20];

        upper_case = isupper(base_name[2]);

        j = strlen(extension);

        /*
        ** Convert extension to proper case (upper or lower)
        **   according to the rest of the filename
        */
        if(upper_case == 0) {
                for(i = 0; i <= j; i++) {
                        buffer[i] = tolower(extension[i]);
                }
        } else {
                for(i = 0; i <= j; i++) {
                        buffer[i] = toupper(extension[i]);
                }
        }
        /* copy directory name to output_name */
        strcpy(out_name, directory);

        /* add base name to output_name */
        strcat(out_name, base_name);

        /* add extension to output_name */
        strcat(out_name, buffer);
}