displaying #define values in C

后端 未结 4 595
孤独总比滥情好
孤独总比滥情好 2021-01-29 04:32

I have a series of #defines from a library file header of this sort:

typedef int Lib_error;   

#define   LIB_ERROR_A      ((Lib_error) 0x0000) 
#define   LIB_ER         


        
4条回答
  •  旧时难觅i
    2021-01-29 05:18

    Warning: The below code piece is just a sample. It can be improvised a lot which is for you to do. : )

    Define a structure like below:

    typedef struct ErrorStorage
    {
      Lib_error err;
      char err_string[100];
    }ErrNoStore;
    
    ErrNoStore arrErr[25];
    
    arrErr[0].err = LIB_ERROR_A;
    strcpy(arrErr[0].err_string, "LIB_ERROR_A");
    /... and so on .../
    

    and later down in the code define a function like this and call it

    void display_error(Lib_error errnum)
    {
      int i = 0;
    
      for(i=0; i<25;i++)
      {
        if(errnum == arrErr[i].err)
        {
           printf("%s\n", arrErr[i].err_string);
        }
      }
    }
    

    }

提交回复
热议问题