473,473 Members | 2,169 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Enum Types

1 New Member
How to change an enum type variable to a string type variable?
Aug 10 '14 #1
2 1220
weaknessforcats
9,208 Recognized Expert Moderator Expert
An enum is an integer value. You just need to change an integer into a string. Use the itoa function in <stdlib.h>.
Aug 10 '14 #2
donbock
2,426 Recognized Expert Top Contributor
Are you seeking to change the integer enum value into a string that matches the name assigned to that value in the enum definition?

The C compiler does not provide any way to do that. You, however, have the option of creating and managing your own lookup table that associates a string with each value. It will be up to you to make sure that the strings in the table actually match the names in the enum definition. For instance, something like this:
Expand|Select|Wrap|Line Numbers
  1. const struct {
  2.    enum Color value;
  3.    const char *name;
  4. } table[] = {
  5.     ...
  6.     { RED, "RED" },
  7.     ...
  8. };
  9.  
The following lookup table mistake does not provoke a compiler warning:
Expand|Select|Wrap|Line Numbers
  1.     { RED, "Yellow" },
Aug 11 '14 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: slot | last post by:
Is it possible to compare "enum" types to basic types like "unsigned short" type at all? Thanks!
4
by: Popoxinhxan | last post by:
Hi guy, i just wondering that is it posible to convert the array of string to enum types dynamically, for example i get the list of countries name from database and would like to convert all of...
1
by: arzewski | last post by:
I don't know what was the reason from a language design point-of-view to allow this, but VB.NET compiler does not flag you (when C# compiler does) when passing an integer value as a parameter to a...
5
by: Alan Cobb | last post by:
Hi, In the managed C++ class below I get compile warning C4677 from VS2003. "signature of non-private function contains assembly private type", even though the managed enum is public. I have...
2
by: Jeremy | last post by:
I would like to limit a field in my datagrid to only accept values in an enum that I have (gDataTypes). To add my column I use: columns.Add("Type", System.Type.GetType("System.String")) ...
2
by: Jeremy | last post by:
I would like to limit a field in my datagrid to only accept values in an enum that I have (gDataTypes). To add my column I use: columns.Add("Type", System.Type.GetType("System.String")) ...
4
by: Pohihihi | last post by:
I read on MSDN that enum is a ref type http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemenumclasstopic.asp but in one of the MS publications enum is said...
0
by: IR | last post by:
Hi, I'm trying to store values of an enum type in a std::bitset container, in a contiguous manner. eg. typedef enum { meValue1 = 0xbaad, meValue2 = 0xbeef,
4
by: Alex | last post by:
Hi, I want to read in enum types from standard input. Unfortunately it does not work. The code is given as follows: #include<iostream> #include<string> #include<fstream> using namespace...
10
by: Charlie | last post by:
I tried to post this before and I apologize if I am repeating myself, but I do not see the post anywhere. But anyway, I have a file, data.c, where I define all of my global variables. I then...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.