📄 strep2.c
字号:
/* Function news1=strep2(s1)
Replaces '*','^' and '/' with '.*', '.^' and './'
CMEX file version of strrep6.m
Author: Mark Hinchliffe
Date: 26 October 1995
*/
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include "mex.h"
/* Gateway routine */
void mexFunction(
int nlhs, Matrix *plhs[],
int nrhs, Matrix *prhs[])
{
char *s1;
char *news1;
int n,i,ctr;
int len;
/* allocate memory and read input string , s1 */
n = mxGetN(prhs[0])+1;
s1 = mxCalloc(n,sizeof(char));
mxGetString(prhs[0],s1,n);
/* count number of occurences of *, / and ^ in string s1 */
ctr=0;
for(i=0; i<n; i++)
{
if((s1[i] == '*') || (s1[i] == '/')
|| (s1[i] == '^'))
{
ctr+=1;}
}
/* allocate memory for new version of string, news1 */
news1 = mxCalloc((n+ctr),sizeof(char));
/* Call string replacement routine */
strrep(news1, s1);
/* Create output string and free memory */
plhs[0] = mxCreateString(news1);
mxFree(s1);
mxFree(news1);
}
strrep(char news1[],char s1[])
{
int i,j;
int len=strlen(s1);
/* create new string */
j=0;
for(i=0; i<len; i++)
{
if((s1[i] == '*') || (s1[i] == '/')
|| (s1[i] == '^'))
{
news1[j] = '.';
j += 1;}
news1[j]=s1[i];
j += 1;
}
return ;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -