OiO.lk Blog C# Get name from enum in pure C
C#

Get name from enum in pure C


I wish to get name from enum by number. Code similar to this:

enum Fruit {
  Apple,
  Banana,
  Peach,
};

printf(Fruit[1]);

Expected result should be ‘Banana’

I found examples for C++ and other languages but I need them for C.

In example are just 3 values in enum, but in real there are many of them and it’s error prone if I need to type them more than one time. I didn’t find a solution to deal it with that in C.



You need to sign in to view this answers

Exit mobile version