Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Tags Active Topics RSS Search Mark Forums Read

Reply
 
Thread Tools Search this Thread
  #1  
Old 05-11-2009
Member
 
Join Date: May 2009
Posts: 3,613
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)
Reply With Quote
  #2  
Old 05-11-2009
Member
 
Join Date: Nov 2005
Posts: 1,323
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.
Reply With Quote
  #3  
Old 05-11-2009
Member
 
Join Date: Nov 2008
Posts: 1,192
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...
Reply With Quote
  #4  
Old 05-11-2009
Member
 
Join Date: Oct 2005
Posts: 2,389
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.
Reply With Quote
  #5  
Old 05-11-2009
Member
 
Join Date: May 2009
Posts: 3,613
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.
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags: , ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "Pointer of file in parameter"
Thread Thread Starter Forum Replies Last Post
Changing Stylus pointer to normal Pointer in Tablet PC Kelley Portable Devices 3 21-06-2011 07:22 PM
Parameter function and generic pointer Rubero Software Development 7 25-09-2010 09:04 PM
Differentiation between void pointer and null pointer Ram Bharose Software Development 5 18-01-2010 12:11 PM
Pointer parameter in a function Chrisch Software Development 4 14-12-2009 10:57 PM
0x80070057 Parameter is Incorrect when copying .DAT file Junn007 Vista Help 0 12-03-2008 02:41 PM


All times are GMT +5.5. The time now is 12:54 AM.