How's a C MEX-file different from a stand-alone ANSI C-file?
A MEX-file has a gateway routine (mexFunction) that transfers data between MATLAB and the C routine. The mexFunction replaces main( ) as the entry-point for the code, and allows it to be called from MATLAB.
A number of MATLAB API routines available for standard I/O and memory management from MEX-files are listed under the "Application Program Interface" link on helpdesk. Definitions for these routines are provided in the header file "mex.h", which must be #included in all your MEX-files.