October 22, 2024
Chicago 12, Melborne City, USA
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

Leave feedback about this

  • Quality
  • Price
  • Service

PROS

+
Add Field

CONS

+
Add Field
Choose Image
Choose Video