I have an s-function in file mySFun.c that calls a function foo() which is implemeted in a separate file myFoo.c. When I write printf statements inside the mdlOutput function in mySFun.c, they work fine. But when I put printf inside function foo() in myFoo.c they don’t show their output in command window.
How can I enable printf functionality when printf is inside another file that is called from an s-function?
The only official way to write to the MATLAB console from a MEX-function is via the function mexPrintf. However, the header file mex.h includes this line:
And simstruc.h includes mex.h. I suspect you are including simstruc.h from mySFun.c, but not from myFoo.c. You can either include simstruc.h or mex.h in your other source files as well (to pick up the #define there), or switch to calling mexPrintf directly.