examples/mystring.c
Go to the documentation of this file.00001 /* 00002 00003 Copyright (C) 2006, 2007 John W. Eaton 00004 00005 This file is part of Octave. 00006 00007 Octave is free software; you can redistribute it and/or 00008 modify it under the terms of the GNU General Public License 00009 as published by the Free Software Foundation; either 00010 version 3 of the License, or (at your option) any later 00011 version. 00012 00013 Octave is distributed in the hope that it will be useful, 00014 but WITHOUT ANY WARRANTY; without even the implied warranty 00015 of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 00016 See the GNU General Public License for more details. 00017 00018 You should have received a copy of the GNU General Public 00019 License along with Octave; see the file COPYING. If not, 00020 see <http://www.gnu.org/licenses/>. 00021 00022 */ 00023 00024 #include <string.h> 00025 #include "mex.h" 00026 00027 void 00028 mexFunction (int nlhs, mxArray *plhs[], int nrhs, 00029 const mxArray *prhs[]) 00030 { 00031 mwIndex i, j; 00032 mwSize m, n; 00033 mxChar *pi, *po; 00034 00035 if (nrhs != 1 || ! mxIsChar (prhs[0]) || 00036 mxGetNumberOfDimensions (prhs[0]) > 2) 00037 mexErrMsgTxt ("expecting char matrix"); 00038 00039 m = mxGetM (prhs[0]); 00040 n = mxGetN (prhs[0]); 00041 pi = mxGetChars (prhs[0]); 00042 plhs[0] = mxCreateNumericMatrix (m, n, mxCHAR_CLASS, 00043 mxREAL); 00044 po = mxGetChars (plhs[0]); 00045 00046 for (j = 0; j < n; j++) 00047 for (i = 0; i < m; i++) 00048 po [j*m + m - 1 - i] = pi [j*m + i]; 00049 }