Checkers provides the vital clue to do this in C or C++. So I have voted his answer.
Here are the details he left out:
// assumes
// company is a pointer to a character sting containing company name
// appname is a pointer to a character string containing application name
// fname is a pointer to a character string cintaining name of file to be created
#include <shlobj.h> // for SHGetFolderPath
#include <direct.h> // for _mkdir
char path[MAX_PATH];
SHGetFolderPath(NULL,CSIDL_COMMON_APPDATA,NULL,NULL,path);
strcat(path,"/");
strcat(path,company);
_mkdir(path);
strcat(path,"/");
strcat(path,appname);
_mkdir(path);
strcat(path,"/");
strcat(path,fname);
// path is now a character string which can passed to fopen