Originally Posted by
MK27
It's your program, but the code you posted does not need to use a char in place of an int. So in terms of "what you have to do" there, you should be using an int.
I agree, so this would be better, I suppose:
Code:
// Program to demonstrate
// array of functions
#include<stdio.h>
// -- FUNCTION PROTOTYPES --
void func1(char,int);
void func2(char, int);
void func3(char,int);
void func4(char,int);
void func5(char, int);
// -- ENDS --
int main(void)
{
// notice the prototype
void (*ptr[5])(char, int);
// arrays are made to point
// at the respective functions
ptr[0]=&func1;
ptr[1]=&func2;
ptr[2]=&func3;
ptr[3]=&func4;
ptr[4]=&func5;
// now the array elements
// point to different functions
// which are called just like
// we access the elements of
// an array
for(int i=0;i<5;i++)
ptr[i]('A',(int) ' ');
return 0;
}
// -- FUNCTIONS DEFINITION --
void func1(char token, int times)
{
printf("Called Func1!\n");
printf("Token = \'%c\' - to repeat %d times\n",token,times);
}
void func2(char token, int times)
{
printf("Called Func2!\n");
printf("Token = \'%c\' - to repeat %d times incremented by 1\n",token,times);
}
void func3(char token,int times)
{
printf("Called Func3!\n");
printf("Token = \'%c\' - to repeat %d times doubled\n",token,times);
}
void func4(char token, int times )
{
printf("Called Func4!\n");
printf("Token = \'%c\' - to repeat %d times doubled except the last time\n",token,times);
}
void func5(char token, int times)
{
printf("Called Func5!\n");
printf("Token = \'%c\' - to repeat %d times tripled\n",token,times);
}