So... after some struggling here we are
Code:
//////////////////////////////
// Set working directory
// lite-C 7.06.1
// by rstralberg
//////////////////////////////
// GameStudio
#include <acknex.h>
// Windows and StdLib stuff
#include <windows.h>
#include <stdio.h>
#define MAX_PATH 260
//////////////////////////////
// Get executable directory
//////////////////////////////
char* GetExeDir(void)
{
char exeDir[MAX_PATH] ;
GetModuleFileName( GetModuleHandle(0), exeDir, (MAX_PATH-1) ) ;
int index = strlen(exeDir)-1 ;
while( index-- > 0 )
{
if( exeDir[index] == '\\' )
{
exeDir[index] = '\0' ;
break ;
}
}
return exeDir ;
}
//////////////////////////////
// Get current directory
//////////////////////////////
char* GetCurDir(void)
{
char curDir[MAX_PATH] ;
_getcwd( curDir, (MAX_PATH-1) ) ;
return curDir ;
}
//////////////////////////////
// Set current directory
//////////////////////////////
void SetCurDir( const char* pstrDir )
{
_chdir( pstrDir ) ;
}
//////////////////////////////
// MAIN PROGRAM ENTRY
//////////////////////////////
function main()
{
char dir[MAX_PATH] ;
// switch dir to executable directory
strcpy( dir, GetExeDir() ) ;
SetCurDir( dir ) ;
// write a file there just to verify where we are
strcpy( dir, GetCurDir() ) ;
printf( "We are now in directory %s. Writing 'Hello' to text.txt there\n", dir ) ;
FILE* fp = fopen( "test.txt", "wt" ) ;
if( fp )
{
fputs( "Hello", fp ) ;
fclose(fp) ;
}
}
This testcode switches to the executable directory,
then writes a file test.txt there.