Main Content

mexPrintf (C and Fortran)

ANSI C PRINTF-style output routine

C Syntax

#include "mex.h"
int mexPrintf(const char *message, ...);

Fortran Syntax

#include "fintrf.h"
integer*4 mexPrintf(message)
character*(*) message


This routine prints a string on the screen and in the diary (if the diary is in use). It provides a callback to the standard C printf routine already linked inside MATLAB® software, which avoids linking the entire stdio library into your MEX file.

In a C MEX file, call mexPrintf instead of printf to display a string.


If you want the literal % in your message, use %% in the message string since % has special meaning to printf. Failing to do so causes unpredictable results.

Input Arguments

expand all

String to display, specified as const char* in C or character*(*) in Fortran. In C, the function supports either UTF-8 or local code page (LCP) encoding and the string can include conversion specifications, used by the ANSI® C printf function. The encoding for both the message text and the conversion arguments must be the same.

In C, any arguments used in the message. Each argument must have a corresponding conversion specification. Refer to your C documentation for printf conversion tables.

Output Arguments

expand all

Number of characters printed including characters specified with backslash codes, such as \n and \b, returned as int in C or integer*4 in Fortran.


See these examples in matlabroot/extern/examples/mex:

See these examples in matlabroot/extern/examples/refbook:

Version History

expand all