开发者

How to make printf work when it is in a separate c file that is called from an s-function?

I have an s-function in file mySFun.c that calls a function foo() which is implemeted in 开发者_JS百科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:

#define printf mexPrintf

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.


printf is a C-library file and as such you do not need to create yours :). you should instead insert the myFoo.h in the mySFun.h file if you will call itz function foo().

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜