calling a function with the variable as a function name please help
Code:
/*
* eg4.c
*
* Created on: Aug 23, 2011
* Author: UshaC1
*/
/*******************************************************************************
** Include Section **
*******************************************************************************/
#include<sys/time.h>
#include<stdio.h>
#include<time.h>
#include<string.h>
#include"stdlib.h"
#define Number_of_Tasks 5 //Number of tasks in a scheduler
/*******************************************************************************
** F U N C T I O N D E C L A R A T I O N S(API) **
*******************************************************************************/
int nTimeInterval;//Global Timer value
void Task_10();
void Task_20();
void Task_30();
void Task_40();
void Task_50();
void Task_60();
void Task_70();
void Task_80();
void Task_90();
void Task_10()
{
printf("Task1 at 10ms executing\n");
printf("Task2 at 10ms executing\n");
}
void Task_20()
{
printf("Task1 at 20ms executing\n");
printf("Task2 at 20ms executing\n");
}
void Task_30()
{
printf("Task1 at 30ms executing\n");
printf("Task2 at 30ms executing\n");
}
void Task_40()
{
printf("Task1 at 40ms executing\n");
printf("Task2 at 40ms executing\n");
}
void Task_50()
{
printf("Task1 at 50ms executing\n");
printf("Task2 at 50ms executing\n");
}
void Task_60()
{
printf("Task1 at 60ms executing\n");
printf("Task2 at 60ms executing\n");
}
void Task_70()
{
printf("Task1 at 70ms executing\n");
printf("Task2 at 70ms executing\n");
}
void Task_80()
{
printf("Task1 at 80ms executing\n");
printf("Task2 at 80ms executing\n");
}
void Task_90()
{
printf("Task1 at 90ms executing\n");
printf("Task2 at 90ms executing\n");
}
void run_task(struct time *val)
{
int i,correction;
float elapsed_time;
static int j=0;//counter
j++;
printf("%d\n",j);
for(i=0;i<Number_of_Tasks;i++)
{
if(val[i].remaining_time == nTimeInterval)
{
clock_t start = clock(); //start a clock
printf(" Execute %s at %d milliseconds \n ",val[i].task,val[i].period);//calling scheduled task here
Task_[val[i].period]();// here i am calling a function that is giving error
elapsed_time=((double)clock() - start) / CLOCKS_PER_SEC; //Time taken to complete a task
/* To check whether my task take more time than nTimeInterval */
if(elapsed_time > nTimeInterval)
{
printf("Time elapsed: %f\n",elapsed_time);
correction=elapsed_time-nTimeInterval; //correction in time
nTimeInterval=nTimeInterval+correction; // adding the correction to nTimeIntervals
printf("%d\n",nTimeInterval);
}
val[i].remaining_time = val[i].period;
}
else
{
val[i].remaining_time -= nTimeInterval;
}
}
}
Here is my code ... in function runtask i need to call my function Task_10,Task_20 or anyother according to the variable var.period so how can i call a function using a variable as a function name ??? .. here i have dome something but its giving error please help me in this concern soon.