通过指针数组的功能 [英] Pass pointer array to function

查看:174
本文介绍了通过指针数组的功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想一个文件指针数组传递给函数(不知道的术语)。任何人都可以请解释为[2]发送正确的方法是什么?谢谢你。

 #包括LT&;&stdio.h中GT;
    #包括LT&;&stdlib.h中GT;    无效openFiles散(文件** []中,文件**出)
    {
        *在[0] =的fopen(IN0,R);
        *在[1] =的fopen(IN1,R);
        *总分=的fopen(走出去,W);
    }    无效的主要()
    {
        FILE *在[2],*出来;        openFiles散(安培;中,&安培;出);
        fprintf中(满分,测试...);        出口(0);
    }


解决方案

尝试:

 无效openFiles散([]中FILE *,文件**出)
{
    在[0] =的fopen(IN0,R);
    在[1] =的fopen(IN1,R);
    *总分=的fopen(走出去,W);
}

和调用它 openFiles散(中,和放大器;出); 。此外,指针数组是不明确的。也许称之为文件指针数组?

I am trying to pass a file pointer array to a function (not sure about the terminology). Could anyone please explain the proper way to send 'in[2]'? Thank you.

    #include<stdio.h>
    #include<stdlib.h>

    void openfiles (FILE **in[], FILE **out)
    {
        *in[0] = fopen("in0", "r");
        *in[1] = fopen("in1", "r");
        *out   = fopen("out", "w");
    }

    void main()
    {
        FILE *in[2], *out;

        openfiles (&in, &out);
        fprintf(out, "Testing...");

        exit(0);
    }

解决方案

Try:

void openfiles (FILE *in[], FILE **out)
{
    in[0] = fopen("in0", "r");
    in[1] = fopen("in1", "r");
    *out   = fopen("out", "w");
}

And call it openfiles (in, &out);. Also, "pointer array" is ambiguous. Perhaps call it "array of FILE pointers" ?

这篇关于通过指针数组的功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆