![]() |
|
#5
|
|||
|
|||
|
Here is a generalized routine good for your situation
and can be easily tailored or adapted to fit most any situation: // EX: OPEN A FILE FOR LOGGING OUTPUT IN ANALYZE MODE. // Find the last '\\' to obtain a pointer to just the base file name part if your buffer contains any path type info // We could just as eaily searched for last '.' to obtain base file name extension pointer. Code:
char *szBuffer = buffer;
PCSTR pszBaseName = strrchr( szBuffer, '\\' );
if ( pszBaseName ) // We found a '\\', so advance to the base FILE name
{
// Increment 1 byte past our pointer
pszBaseName++;
strncpy(pszBaseName, "Asprlog.txt\0", 12); // we need 12 to include '\0'
null char
//replace base file name with newname , here you could have appended
bak or BAK extension if you had searched on the '.' char Ex: as so:
strncpy(pszBaseName, "bak\0", 4);
}
FILE * pFile;
pFile=fopen(szBuffer,"wt"); // open for write
cheers! |
|
|