Hi,
1.i have a char * fileName ="myFile" and a array function pointer void (*fileptr[5])(void).
2. i have five function:
void myFile1();
void myFile2();
void myFile3();
void myFile4();
void myFile5();
3.Inside a for loop am appending char * fileName
<pseudocode>:loop for i till i =5
filename = filename+'i'
do process
and loop back
4.My problem is: instead of assignin the funct pointer as fileptr[i]=myFile1
I WANT TO USE char *filename to do so.So that in every loop i can assign a diffrent function name to the array of function pointers.
fileptr[0]=filename1
fileptr[1]=filename2
fileptr[2]=filename3
fileptr[3]=filename4
.
.
since i am trying to to use the char * to generate the function name, i am unable to assogn the adres of the function to the function pointer. Can it be done??
yes i undesatnds that.So is there any way i can do it in for loop?
My prob is that i ll have to assign address to all function poinetr(more than 15) an in future if more function gets added then maintan is prob.So any suggestion???
As you already know, you're current approach isn't going to cut it. But there may be ways to do this. But it all depends on what exactly these functions are, where they come from and how they're used. In the end, the functions and the list they go into must be encapsulated by something.
If your functions lived in seperate DLLs/Shared Libraries, the app could scan some directory for Modules that exported a function with a fixed name. If it finds it, it adds its address to your list of functions.
Or if the actuall functions were a method in a class, you build a class hierarchy with all your functions, and make each class register itself into the list on construction.
There's a variety of ways of automating this, but it all depends on what you're doing. And also, it may be simpler to just add them to the list yourelf.