How to convert an enum type variable to a string?
问题 How to make printf to show the values of variables which are of an enum type? For instance: typedef enum {Linux, Apple, Windows} OS_type; OS_type myOS = Linux; and what I need is something like printenum(OS_type, \"My OS is %s\", myOS); which must show a string \"Linux\", not an integer. I suppose, first I have to create a value-indexed array of strings. But I don\'t know if that is the most beautiful way to do it. Is it possible at all? 回答1: There really is no beautiful way of doing this.