vc++调用MATLAB complier生成的C动态链接库(输入参数为字符类型)

22 篇文章 0 订阅

强大的混编,这次用它来实现传说中的“河内”游戏(Hanoi),包括了子函数调用和函数递归调用,且输入参数有字符型常量。

在这里要强烈鄙视一下张德丰的《MATLAB与外部程序接口编程》,内容又落后又烂,居然还停留在6.5的版本,现在很多接口函数都已经变了不少。

 

 

 

 

m代码:

function hanoi(n,one,two,three)
if n==1
    move(one,three);
else
    hanoi(n-1,one,three,two);
    move(one,three);
    hanoi(n-1,two,one,three);
end
end

function move(getone,putone)
fprintf('%c',getone);
fprintf('-->');
fprintf('%c/n',putone);
end

 

c代码:

#include "stdio.h"
#include "hanoi.h"

void main()
{
    if (!mclInitializeApplication(NULL,0))
    {
        printf("error!");
        exit(1);
    }
    if (!hanoiInitialize())
    {
        printf("error!");
        exit(1);
    }


    mxArray *n,*one,*two,*three;
    int N=3;
   

    n=mxCreateDoubleScalar(N);
    one=mxCreateString("A");
    two=mxCreateString("B");
    three=mxCreateString("C");



    mlfHanoi(n,one,two,three);

    mxDestroyArray(n);
    mxDestroyArray(one);
    mxDestroyArray(two);
    mxDestroyArray(three);

    hanoiTerminate();
    mclTerminateApplication();
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值