Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Dynamic function name in c

Status
Not open for further replies.

varunme

Advanced Member level 3
Advanced Member level 3
Joined
Aug 10, 2011
Messages
741
Helped
17
Reputation
36
Reaction score
17
Trophy points
1,318
Visit site
Activity points
5,765
Can we program like this, is there any otherway to achive this ?

Code:
int u;
void dext[1] ()
{        
         UART1_Write_Text("One");              // send text string to UART
}

void dext[2] ()
{        
         UART1_Write_Text("Two");              // send text string to UART
}

void dext[3] ()
{         
         UART1_Write_Text("Three");              // send text string to UART
}


void main()
{
        for(u=1;u<=10;u++)
             {
                 dext[u] ();

             }

}

The strings "ONE", "TWO", "THREE" are just examples here , i want to send dynamic text calculated from a loop
i want to know an alternative of switch case, as i think it will reduce the size of the program
 
Last edited:

Hello

code
void Func1(void);
void Func2(void);
void Func3(void);

void (*Fct[])(void)={Func1,Func2,Func3};

void Func1(void)
{
UART1_Write_Text("One");
}

void Func2(void)
{
UART1_Write_Text("two");
}

void Func3(void)
{
UART1_Write_Text("three");
}


void main(void)
{
char I;
for (I=0;I<3;I++)
(*Fct)();

}
 
Last edited:
  • Like
Reactions: varunme

    varunme

    Points: 2
    Helpful Answer Positive Rating
Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top