Pointer of file in parameter
I'm under Windows XP, IDE devc++, and I made a program in C.
Here I have several pointers that points to file of same type: I should point the file or will be recording TV channels. I would therefore be grouped in a "table file pointer" for use by more easier (zapping between channels for example).
So I did
Code:
FILE* FpChannel[NumberOfChannels]= { };
the number of channels being previously established with a #define NumberOfChannels 5
So my question is this: how to pass the "pointer array" argument in a function? And how to write the prototype for this function? (this is a function that would do a fopen individual files corresponding to the pointer: it makes eg FpChannel[i] = fopen (cNameFileClient, "w"); what I want to report it works very well leaving in the main function)
Re: Pointer of file in parameter
I do not see very well the worries.
You create your function with a prototype like:
Code:
void fopen_array(FILE** FpChannel)
That should allow you to make your fopen problem without a priory.
Re: Pointer of file in parameter
Want to pass an array of anything (eg "noMatterWhat tab [10]") to a function, well you simply pass the variable name to the => ex: fct(tab)
The function will be reported as receiving a pointer to the type in question => void fct (noMatterWhat *pt)
At now, what's that "noMatterWhat"? Its a "FILE *" where the response absolute => void fct (FILE * pt)
However, the equivalent array / pointer works only for the last dimension. For other dimensions, an array is a table.
Example: A rectangle int 8x10 => int rect [8] [10]
If you pass this "rect" to a function, it can be declared as
- Void fct (int rect [8] [10])
- Void fct (int * rect [10])
But in no case be declared void fct (int ** rect). This is because to address the element [x] [y], the compiler needs to know the width to calculate the position. and "int ** rect", there is no indication of largeness...
Re: Pointer of file in parameter
But absolute, since you pass a pointer to an array at large then you must become accustomed to pass the array size in parameter (size_t n). I may be wrong but I think the compiler would give you an error.
Re: Pointer of file in parameter
Yes you may be correct, but then I do not know the size of the array, they are pointers to files of which I do not know the size. In any case it works. Thanks for the solution and other information provide that helps me a lot in my code.