1. Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.
    Dismiss Notice

enum with case , switch statment in c

Discussion in 'Microcontrollers' started by Parth86, Jun 5, 2017.

  1. Parth86

    Parth86 Member

    Joined:
    Dec 25, 2011
    Messages:
    513
    Likes:
    5
    Hello
    I have written original code for three task's. Now I want do one by one in program. I found on internet that I have to use enum case and switch statement in program. Look at below program it's hand made program just for understanding. I understand the case and switch statement in program. I don't understand what does enum do in program and use of enum in program
    Code (c):
     
    typedef enum
    {
    task_1 =0,
    task_2,
    task_3
    }my_state_t;
    my_task_t task = task_1;

    int main ()
    {
    unsigned int task;
    switch(task)
    {
    case 1:
    if my_task_t task = task_1
    Do task 1 ();
    break;
    case 2:
    if my_task_t task = task_2
    Do task 2 ();
    Break;
    case 3:
    my_task_t task = task_3
    Do task 3 ( );
    }
     
     

Share This Page