473,385 Members | 1,780 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Run time function call problem

Hello Folks!!!!!

Here is a question ...

I have two functions

void fun1(int i )
{
printf("%d",i);
}

void fun2(float f)
{
printf("%f",f);
}

I want to call the fun1 if the user-input is 1 and fun2 if the user-input is 2
I need to do this without using if-else, switch or conditonal operators... Any way to accomplish this ???
Jul 29 '08 #1
4 1198
Banfa
9,065 Expert Mod 8TB
Try an array of pointers to functions.
Jul 29 '08 #2
Try an array of pointers to functions.
Array of pointers to functions doesn't work here because the functions are of different types (arguments are of different types).... Please suggest any other way...
Sep 22 '08 #3
newb16
687 512MB
Expand|Select|Wrap|Line Numbers
  1. (input-2)||(printfloat(2.5),1);
  2. (input-1)||(printint(3),1);
  3.  
Sep 22 '08 #4
donbock
2,426 Expert 2GB
You want your program to do one of two things based on an input value. This is by definition conditional code. You can't avoid conditional operators; the best you can do is hide them as suggested by the array index and || suggestions posted earlier.

What topics were being discussed in your class around the time this assignment was given out?

Has your teacher provided a specific definition of what the "conditional operators" are? Perhaps there's a loophole if that definition isn't complete.

What argument is passed to these functions? That is, what number do you expect to see printed by them? Perhaps you can define wrapper functions for each of them such that the wrappers have identical prototypes; then you could use function pointers.

Cheers,
donbock
Sep 22 '08 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Mike Alexeev | last post by:
Hi all, I have come across very strange behavior of the return value of the time() function. Below is the program to illustrate the problem: The value of NOW somehow changes after the call to the...
17
by: newbiecpp | last post by:
I have hard time to understand run-time environment. Let assume that I have a program that has a simple variable alpha. When this variable is statically allocated, the compiler can use the...
4
by: Christine | last post by:
I've implemented a countdown timer for a tutorial web page that should give the user 45 minutes to complete the test, only to find that the timer is slowly 'losing' time. On average, it actually...
2
by: Terry | last post by:
I have used the code provided in the PreciseDateDiff function at the following Access Web link to calculate the time change date (from Daylight to Standard time and vice versa): ...
3
by: Servé Lau | last post by:
I encountered a situation today where time(NULL) returned -1. This was because at the point of the call the function could not read from the bus because it was locked by another process. I got the...
17
by: Razzel | last post by:
I created this as a test: #include <time.h> main(){ printf(X1: %s\n", putim()); printf(X2: %s\n", putim()); } putim() { time_t t; time(&t); return(ctime(&t));
11
by: zhong | last post by:
Error Message: Run-Time Check Failure #0 - The value of ESP was not properly saved across a function call. This is usually a result of calling a function declared with one calling convention...
12
by: Spitfire | last post by:
I've a requirement to find the elapsed time between two function calls. I need to find the time elapsed accurate to 1 millisecond. The problem I'm facing right now is that, I'm using the 'time()'...
2
by: r_ahimsa_m | last post by:
Hello, I am learning PHP5. I need to parse XML file and I found a solution in some book on PHP5 ("PHP5 Programming" by Rasmus Lerdors and others). Unfortunately I have two problems that I don't...
27
by: CodeMonk3y | last post by:
gotta question on sizeof keyword does the sizeof keyword calcuates the size at compile time or run time ?? -- Posted on news://freenews.netfront.net - Complaints to news@netfront.net --
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.