How To Call A Function Again In Case Statement In C Language?
If there are two cases. Case1 has a call to function a() and case2 has a call to function b(). Now I want to access the function a() in case2 without declaring its name {a()} mean calling the function not by its name but some other method.
2 Answers - Sort by: Date | Rating
If you need to call a() as the last thing in case 2, you could code your switch statement with Case 2 first, then Case 1 below it. If you then avoided calling break at the end of the Case 2 code, execution would continue on into the Case 1 code, thus calling a(). Of course, if there were any more cases below Case 1, their code would be called too unless you put a break after the a() in Case 1. Also it doesn't work if you need to do something in Case 2 after calling a(). It's incredibly bad coding style, too, but if, for some reasons, you really wanted to do that, it might be what you need.
0
0
As I under stand you want to call function from function b but not use the normal a() method to call. Correct?
Well you could call using a pointer to the function. I do not have access to a compiler here but the code would look something like this:
static void a(char message);
void (*ptr2a)(char) = a;
static void b(void );
void main( )
{
for(int x = 0; x < 2; ++x)
{
switch(x)
{
case 0 : A((char)"Good Morningn");
cycle;
case 1 : B();
cycle;
}
}
}
void a(char message)
{
printf("%s",message);
}
void b(void)
{
ptr2a((char)"and good night n");
}
Well you could call using a pointer to the function. I do not have access to a compiler here but the code would look something like this:
static void a(char message);
void (*ptr2a)(char) = a;
static void b(void );
void main( )
{
for(int x = 0; x < 2; ++x)
{
switch(x)
{
case 0 : A((char)"Good Morningn");
cycle;
case 1 : B();
cycle;
}
}
}
void a(char message)
{
printf("%s",message);
}
void b(void)
{
ptr2a((char)"and good night n");
}
0
0
Don't know why the capital A and B in the case statements. It is lower case in the code. But then blurtit has their own formatting rules.
- Can Anyone Give Me The Code In C++ For Reversing A Linked Circular Queue Using Pointers?
- Write A Program In C To Find The Area Of Rectangle, Area Of Circle, Area Of Cube Using Overloading Function?
- State The Output That Will Be Produced By The Following C++ Program : #include #include Int Square (int Y ) { Return Y*y; } Void Main ( ) { For(int X=1;x?
- What Is The Input Electric On A Dsi?
- What Are The Classified Input In Economists?
- What Are The Classified Input Had Economics?
- What Is Input Technologies Trends?
- What Are The Input Technologies?
- What Floods Include Weatherwise?
- Why Are Economists Input As Timeless?
- What Is An Example Of An Input Devise?
- How To Make A Simple Programming?
- Where Can I Learn DirectX Or OpenGL In C++?
- What Does |= And &= Means In C++?
- What Is Input From Technology Means?
- Write A Program In C/C++ To Implement Cohen-Sutherland Line Clipping Algorithm. In This Implementation, Consider Two Cases Of A Line: Totally Visible, Totally Invisible, Against The Rectangular Clipping Window?
- Can Somebody Tell Me Why This Code Will Not Compile: #include "Stdafx.h" //added This Include #include //added Stream To Io Using Namespace Std; Int Main() { //declare Variables Int Choice=0; Std::cout?
- Sample Program Which Requires 2 Numbers, Input 1 And Input Which Will Be The Start Of A Fibonacci Series?
- Sample Program Which Requires 2 Input For Fibonacci Series?
- What Is Input Stream?
- How Do I Input Answers?
- How Do I Write A Program To Compute The Standard Deviation Of 5 Input Values. Create A Constant For The Number Of Values (5). Ask The User For The Numbers. Next, Compute The Mean (sum Divided By 5)?
- What Are Link Lists In C++?
- Where Can I Download C++ Programmes File?
- Which Output Statement Is Used In C++ Language?
- Which Statement Is Used For Input In C++ Language?
- Explain The "If" Statement Use In C++ Language?
- What Did Graham Sankey Admit To In A Statement Regarding The Case Of Michael Shields?
- Can You Explain The Statement That Language Is Symbolic And Person Centered?
- Why We Use # Function In C Language?
- I Know Civil Case Who Do I Call Arnold?

New Comment - Comments are editable for 5 min.