MATLAB: How to process user inputs in the MEX-file

MATLABmexstdinstdout

I would like to read user input via the C language's user input functions, or via third-party API routines that allow the handling of user input events.

Best Answer

The recommended method of obtaining user input in a MEX-file is to use the mexCallMATLAB MEX-API function to call MATLAB's INPUT function.
The "stdin" and "stdout" file descriptors may not function as expected from within a MEX-file, and as such, any C or Fortran routines that use these descriptors may not behave as expected.
MathWorks does not test or officially support the use of third-party APIs for obtaining user input events from within MEX-files. Use of these APIs in MEX code may result in MATLAB instability.