How To Call A Function Again In Case Statement In C Language?

3 Answers

John Nawrocki Profile
John Nawrocki answered
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");
}
thanked the writer.
John Nawrocki
John Nawrocki commented
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.
Anonymous Profile
Anonymous answered
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.
Anonymous Profile
Anonymous answered
Hi
In my program the error is coming like " Call to undefined function 'x' in function main(), what is this error? Please explain me.

Answer Question

Anonymous