📄 revord.c
字号:
/* $Revision: 1.10.6.4 $ */
/*=================================================================
* revord.c
* example for illustrating how to copy the string data from MATLAB
* to a C-style string and back again
*
* takes a row vector string and returns a string in reverse order.
*
* This is a MEX-file for MATLAB.
* Copyright 1984-2006 The MathWorks, Inc.
*=============================================================*/
#include "mex.h"
void revord(char *input_buf, mwSize buflen, char *output_buf)
{
mwSize i;
if (buflen == 0) return;
/* reverse the order of the input string */
for(i=0;i<buflen-1;i++)
*(output_buf+i) = *(input_buf+buflen-i-2);
}
void mexFunction( int nlhs, mxArray *plhs[],
int nrhs, const mxArray *prhs[])
{
char *input_buf, *output_buf;
mwSize buflen;
/* check for proper number of arguments */
if(nrhs!=1)
mexErrMsgTxt("One input required.");
else if(nlhs > 1)
mexErrMsgTxt("Too many output arguments.");
/* input must be a string */
if ( mxIsChar(prhs[0]) != 1)
mexErrMsgTxt("Input must be a string.");
/* input must be a row vector */
if (mxGetM(prhs[0])!=1)
mexErrMsgTxt("Input must be a row vector.");
/* get the length of the input string */
buflen = (mxGetM(prhs[0]) * mxGetN(prhs[0])) + 1;
/* allocate memory for output string */
output_buf=mxCalloc(buflen, sizeof(char));
/* copy the string data from prhs[0] into a C string input_ buf. */
input_buf = mxArrayToString(prhs[0]);
if(input_buf == NULL)
mexErrMsgTxt("Could not convert input to string.");
/* call the C subroutine */
revord(input_buf, buflen, output_buf);
/* set C-style string output_buf to MATLAB mexFunction output*/
plhs[0] = mxCreateString(output_buf);
mxFree(input_buf);
return;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -