Read the current project directory in C-Code
Question
How can I determine the current CarMaker project directory when using the C-Code interface?
Solution
The CarMaker Simulation Program (e.g. CarMaker.win64.exe) always requires a valid CarMaker project folder as its working folder.
This is the case if the Simulation Program is started via the CarMaker-GUI but also if no GUI is used (if the Simulation Program is started without providing a valid project directory, an error is thrown).
Please note that this is not the case when using CarMaker for Simulink, where the working directory or Matlab is usually the src_cm4sl folder inside the CarMaker project.
This means that in order to determine the project directory, in most cases, you simply need to determine the current working folder of the executable.
To do so you can use the standard C-Code function getcwd:
Linux:
#include <unistd.h>
char *getcwd(char *buf, size_t size);
Windows:
#include <direct.h>
char *_getcwd(char *buf, int _SizeInBytes);
- Date: 20.10.2020
- Product: CarMaker
- Version: 12.0
- Component: C-Code Interface
- Language: English
Tags
Simulation Programgetcwd
Current Working Directory