[英]c-function fprintf variable file pointer
I have multiple file pointers. 我有多个文件指针。 During a loop I want to print something into a certain file. 在循环期间,我想将某些内容打印到某个文件中。 Which file depends on the loop pass. 哪个文件取决于循环传递。
fprintf(stream,"v t \n");
With "stream" I choose the file. 使用“流”,我选择文件。 Is it possible to pass a certain array element as stream? 是否可以将某个数组元素作为流传递?
For example: 例如:
FILE *vx;
FILE *vy;
FILE *vz;
vx=fopen("vx.txt","w");
vy=fopen("vy.txt","w");
vz=fopen("vz.txt","w");
pointer[]={vx,vy,vz};
while(n<4)
{
funck(n, k, v, w, h);
fprintf(pointer[n-1],"v t \n");
n+=1;
}
Is it a possible to save file pointer in an array? 是否可以将文件指针保存在数组中? Is this a good solution? 这是一个好的解决方案吗?
Yes, it's possible, as long as you pass a variable of type FILE *
to fprintf()
. 是的,只要您将FILE *
类型的变量传递给fprintf()
就有可能。
The array type must be of type FILE*
, since the array store pointers to a referenced FILE
object ( FILE*
). 数组类型必须是FILE*
类型,因为数组存储了指向引用的FILE
对象( FILE*
)的指针。
If you were using pointers, the pointer's type must have been be FILE**
, since it's a pointer( *
) to a referenced FILE
object ( FILE*
). 如果你使用指针,指针的类型必须一直BE FILE**
,因为它是一个指针( *
),以引用的FILE
对象( FILE*
)。
Yes, it is possible. 对的,这是可能的。 Type your array with FILE *. 使用FILE *输入数组。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.