Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

PLEASE HELP !!!!!!!!!!!

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
I AM A PROGRAMMER OF SATYAM,
MY NAME IS K.SUBBARAO

MY QUESTION IS

I have 100 functions with different names.I will have to call from
main function by accepting the name of the function from the user.
for example user entered add ,then it will call add function which
is immediately below the main funtion.For that i am using 100
comparission statements.Is there any other alternative so that
we can call the corresponding function without using comparision.

problems i am getting:

1.user giving name of the funtion which is accepted into a string
buffer,how can you call that function when you know the name of
the function when it running.
2.only using c language.
 
You can do it but the type and number of arguments arguments to these function shoud be same.

1. If so then you can create an array of function pointers and then strore the address of all the functions in this array.

2. Store the name of all the function in char array. Condition : the order of the function address in the first array and the function names in the second array should same.

Eg : void (*p[100])(void);

3. get the function name from the user and check its existance in the functin_name array and findout the index.

Eg : char name[100][20];

4. use this resultant index in the function_pointer array and get the address of the function.

Eg : p[0]();

5. Now using this address you can call the functions

Maniraja S
 

THANK YOU MANIRAJA S,
I AM SUBBARAO FROM SATYAM COMPUTERS(HYDERABAD,INDIA),

THIS IS OK. CAN WE CALL DYNAMICALLY A FUNCTION IN C LANGUAGE LIKE C++(WHICH SUPPORTS RUNTIME CALLING FUCTION)?,
CERTIANLY WE CAN NOT CALL A FUNCION WHEN IT IS IN EXECUTION.
SO IS THERE ANY POSIBILITY TO DEVELOP CODE, WHICH SUPPORTS
DYNAMIC CALLING IN C.BECAUSE IN THAT ABOVE SOLUTION ALSO I REQUIRE COPARISIONS AND STORING FUN NAMES.ANY WHY WHICH
FUNCTION TO CALL I AM GIVING NAME OF THE FUNTION.SO PLEASE
TRY IT AND GIVE ME SOLUTION.
BY
SUBBARAOK.(PHONE:3306767 EXT 7682).
 
THANK YOU FRIEND,
I AM SUBBARAO FROM SATYAM COMPUTERS(HYDERABAD,INDIA),
CAN WE CALL DYNAMICALLY A FUNCTION IN C LANGUAGE
LIKE C++(WHICH SUPPORTS RUNTIME CALLING FUCTION)?,CERTIANLY WE CAN NOT CALL A FUNCION WHEN IT IS IN EXECUTION.
SO IS THERE ANY POSIBILITY TO DEVELOP CODE,
WHICH SUPPORTS DYNAMIC CALLING IN C.
BY
SUBBARAOK.
(PHONE:3306767 EXT 7682).
 
Subbaraok,

NO NEED TO SHOUT MATE! Maniraja stated above that you can have pointers to functions. Then you can call a function from that pointer, based on some input from the user.

Presumably at the moment you have a huge switch statement with 100 cases, one per function.. Read up on pointers to functions in any decent C manual.

Loon

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top