小编Max*_*ert的帖子

使用参数调用perl例程

我需要在我的C程序中调用perl例程.perl例程采用以下参数:$a, $b, $c,where $a$b是整数,$c是一个字符串(可能包含二进制字符).根据perlcall,这里是打电话的方式.

I32 call_sv(SV* sv, I32 flags);
I32 call_pv(char *subname, I32 flags);
I32 call_method(char *methname, I32 flags);
I32 call_argv(char *subname, I32 flags, char **argv);
Run Code Online (Sandbox Code Playgroud)

似乎我只能使用call_argv(...),但有两个问题

  • 如何将整数传递给perl例程
  • 如何将(二进制)字符串传递给perl?

希望有一个像这样的功能

I32 call_argv(char *subname, I32 flags, int numOfArgs, SV* a, SV* b, SV *c ...);
Run Code Online (Sandbox Code Playgroud)

c perl xs

7
推荐指数
1
解决办法
390
查看次数

使用while循环计算前n个Fibonacci数的程序

当我运行它并输入一个数字时,它只是不停地重复它.例如,如果我放3,它会做3 3 3 3 3但不停止

int main()
{
int current=0, prev=1, prev2=1, fibnum;
cout << "Enter the number of Fibonacci numbers to compute: ";
cin >> fibnum;
if (fibnum <=0)
{
    cout << "Error: Enter a positive number: ";
}
while (fibnum > 0){
    current = prev + prev2;
    prev = prev2;
    prev2 = current;
    current++;

    cout << "," << fibnum;
    cout << endl;
}
return 0;
}
Run Code Online (Sandbox Code Playgroud)

c++ putty fibonacci while-loop

0
推荐指数
1
解决办法
2万
查看次数

标签 统计

c ×1

c++ ×1

fibonacci ×1

perl ×1

putty ×1

while-loop ×1

xs ×1