I am implementing a mex script, where at some point I need to call a function from an external library. This function is as simple as printing the provided input, which is though collected as arguments and passed to vprintf()
. See below:
void PrintInfo(const char *format, ...)
{
va_list args;
va_start(args, format);
vprintf(format, args);
va_end(args);
}
The issue now is that once I call the PrintInfo()
function inside my mex script for example:
PrintInfo("Give me %i apples.\n", 3);
I am not able to get any output in the matlab's console prompt, like I do when I used printf()
or cout
instead. I was trying to figure it out myself but no chance so far, thus I would appreciate if someone could explain me what is the issue and how I can bypass it.
Altering the library's files is not possible, thus I am looking for a solution that can be done on mex script from my side.
Update: For example in the following mex script from the printing functions only the PrintInfo()
does not show anything:
#include "mex.h"
// cpp system headers
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cstdarg>
using namespace std;
void PrintInfo(const char *format, ...)
{
va_list args;
va_start(args, format);
vprintf(format, args);
va_end(args);
}
void foo()
{
printf("Vector size is: %i \n", 5);
}
void foo1(const char *format, int sz)
{
printf(format, sz);
}
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) {
PrintInfo("Vector size is: \n", 10);
foo();
foo1("Vector size is: %i \n", 2);
cout << "Vector size is:" << 4 << endl;
}