![]() |
| | #1 |
| Registered User Join Date: Feb 2009
Posts: 14
| Printing values from Enum Consider the following. Code: enum meat {beef, pork, chicken, salmon };
Code: printf("%d", beef);
|
| Raskalnikov is offline | |
| | #2 |
| subminimalist Join Date: Jul 2008 Location: NYC
Posts: 3,944
| Not As Far As I Know. Great name tho, I hope you don't kill anyone with an axe
__________________ Accuracy and integrity mean nothing if you don't make it past the censors...PYTHAGORAS |
| MK27 is offline | |
| | #3 |
| Registered User Join Date: Oct 2008 Location: TX
Posts: 1,262
| AFAIK I don't think so since those symbolic names don't exist at runtime. |
| itCbitC is offline | |
| | #4 |
| CSharpener Join Date: Oct 2006
Posts: 5,242
| you need to maintain the list of strings yourself Code: const char* meetstr[]={"beef","pork", "chicken", "salmon"};
printf(%s",meetstr[beef]);
__________________ If I have eight hours for cutting wood, I spend six sharpening my axe. |
| vart is offline | |
| | #5 |
| Kernel hacker Join Date: Jul 2007 Location: Farncombe, Surrey, England
Posts: 15,686
| Surely that should be "meatstr"? And as stated, the symbolic names do not exist in the binary unless you specifically produce code to translate the enum to strings. -- Mats
__________________ Compilers can produce warnings - make the compiler programmers happy: Use them! Please don't PM me for help - and no, I don't do help over instant messengers. |
| matsp is offline | |
| | #6 |
| CSharpener Join Date: Oct 2006
Posts: 5,242
|
__________________ If I have eight hours for cutting wood, I spend six sharpening my axe. |
| vart is offline | |
| | #7 | |
| Complete Beginner Join Date: Feb 2009
Posts: 312
| Quote:
If you need to start at a different value than 0, add an offset. If the integer values don't increase by 1, build your own structure for storing the stuff: Code: typedef struct {
int index;
char buf[1024];
} kv;
kv stuff[1024];
// ...
stuff[0].index = 17;
strcpy(stuff[0].buf, "snafu");
Philip | |
| Snafuist is offline | |
| | #8 |
| Registered User Join Date: Feb 2009
Posts: 14
| Thanks for the replies. The exercises from the enum/typdef chapter in my C book asked for a lot of enum value printing. Consequently, this chapter is before the array chapter so it took a lot of switch statements. Oh and thanks MK27. I'm picking up C in jail, Sonia says its good for me. |
| Raskalnikov is offline | |
| | #9 |
| subminimalist Join Date: Jul 2008 Location: NYC
Posts: 3,944
| Don't catch consumption!
__________________ Accuracy and integrity mean nothing if you don't make it past the censors...PYTHAGORAS |
| MK27 is offline | |
![]() |
| Tags |
| enum printf value |
| Thread Tools | |
| Display Modes | |
|
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| C# Printing Problem | silverlight001 | C# Programming | 0 | 03-23-2009 01:13 AM |
| Controlling variable values by printing on file | p3rry | C Programming | 8 | 12-17-2008 10:09 AM |
| Need help with project | chrisa777 | C++ Programming | 5 | 06-19-2006 05:01 PM |
| Printing enum field symbolically | pdc | C Programming | 3 | 07-05-2005 12:51 AM |
| Switch case and enum help | SomeCrazyGuy | C++ Programming | 9 | 04-21-2005 08:53 PM |