gpt4 book ai didi

c - 将指针数组传递给函数

转载 作者:太空宇宙 更新时间:2023-11-03 23:31:08 25 4
gpt4 key购买 nike

我正在尝试将文件指针数组传递给函数(不确定术语)。谁能解释发送“in[2]”的正确方法?谢谢。

    #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);
}

最佳答案

尝试:

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

并将其称为打开文件(输入、输出);。此外,“指针数组”是不明确的。也许称它为“FILE 指针数组”?

关于c - 将指针数组传递给函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15151803/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com