GIDForums  

Go Back   GIDForums > Computer Programming Forums > C Programming Language
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 20-Jul-2005, 04:57
kobi_hikri's Avatar
kobi_hikri kobi_hikri is offline
Regular Member
 
Join Date: Apr 2005
Location: Israel
Posts: 431
kobi_hikri has a spectacular aura aboutkobi_hikri has a spectacular aura about

printing an enumeration .


Given the definition :
CPP / C++ / C Code:
typedef enum {a,e,r} command_type;

What would be the appropriate way to print the enumeration itself (not the number that represents each value) ?
Is it possible without a switch ?

Kobi.
  #2  
Old 20-Jul-2005, 08:15
QED's Avatar
QED QED is offline
Member
 
Join Date: Feb 2005
Location: Hudson Valley, NY
Posts: 231
QED is a jewel in the roughQED is a jewel in the roughQED is a jewel in the rough
To answer your second question: yes, it is possible without switch, by using if-else.
Okay, not that funny. But, of course, this means that the answer to your first question is: by using some conditinoal statements, like switch or if-else.

Unfortunately, those are your choices. (As far as I know, of course.)

Matthew
  #3  
Old 20-Jul-2005, 08:16
Dave Sinkula Dave Sinkula is offline
Member
 
Join Date: Apr 2005
Posts: 199
Dave Sinkula will become famous soon enough
  #4  
Old 20-Jul-2005, 08:25
kobi_hikri's Avatar
kobi_hikri kobi_hikri is offline
Regular Member
 
Join Date: Apr 2005
Location: Israel
Posts: 431
kobi_hikri has a spectacular aura aboutkobi_hikri has a spectacular aura about
Quote:
Originally Posted by QED
To answer your second question: yes, it is possible without switch, by using if-else.

Not nice, making fun of me :-(

Kobi.
  #5  
Old 20-Jul-2005, 08:27
QED's Avatar
QED QED is offline
Member
 
Join Date: Feb 2005
Location: Hudson Valley, NY
Posts: 231
QED is a jewel in the roughQED is a jewel in the roughQED is a jewel in the rough
Quote:
Originally Posted by kobi_hikri
Not nice, making fun of me :-(

Kobi.
Woah, there. It was a joke, but not to poke fun at you personally.

Matthew
  #6  
Old 20-Jul-2005, 09:19
QED's Avatar
QED QED is offline
Member
 
Join Date: Feb 2005
Location: Hudson Valley, NY
Posts: 231
QED is a jewel in the roughQED is a jewel in the roughQED is a jewel in the rough
Quote:
Originally Posted by Dave Sinkula
Ugh... but the char array example above the macro one looks a little nicer to me, although not something I'd use often, and not easily maintained.

Matthew
  #7  
Old 20-Jul-2005, 09:31
Dave Sinkula Dave Sinkula is offline
Member
 
Join Date: Apr 2005
Posts: 199
Dave Sinkula will become famous soon enough
Quote:
Originally Posted by QED
Ugh... but the char array example above the macro one looks a little nicer to me, although not something I'd use often, and not easily maintained.
They both do the same thing -- and the macro is used to handle the maintainance. Once you understand how it works, or if you just trust it, all you change is this part:

CPP / C++ / C Code:
/* Macro Binding */
MACRO(ALPHA, "This is a description of this element.")
MACRO(BETA,  "The next item has no description.")
MACRO(GAMMA, "")
MACRO(DELTA, "")
The text is automatically changed, etc.
  #8  
Old 20-Jul-2005, 09:45
QED's Avatar
QED QED is offline
Member
 
Join Date: Feb 2005
Location: Hudson Valley, NY
Posts: 231
QED is a jewel in the roughQED is a jewel in the roughQED is a jewel in the rough
Quote:
Originally Posted by Dave Sinkula
They both do the same thing -- and the macro is used to handle the maintainance.
...
The text is automatically changed, etc.

Got it. I have rarely used macros, so I don't typically think in that way. Very good little technique to know, should I ever need or want to do such a thing. Fortunately, I never have.

Matthew

Edit: I take that back. I have done a similar thing, but in Java and the maintenance (since there are no macros) is annoying.
  #9  
Old 20-Jul-2005, 09:58
kobi_hikri's Avatar
kobi_hikri kobi_hikri is offline
Regular Member
 
Join Date: Apr 2005
Location: Israel
Posts: 431
kobi_hikri has a spectacular aura aboutkobi_hikri has a spectacular aura about

I know :-)


Quote:
Originally Posted by QED
Woah, there. It was a joke, but not to poke fun at you personally.

Matthew

I wouldn't think anything else.
  #10  
Old 20-Jul-2005, 10:02
kobi_hikri's Avatar
kobi_hikri kobi_hikri is offline
Regular Member
 
Join Date: Apr 2005
Location: Israel
Posts: 431
kobi_hikri has a spectacular aura aboutkobi_hikri has a spectacular aura about

About macros


Quote:
Originally Posted by QED
Got it. I have rarely used macros, so I don't typically think in that way.

I recently started using macros (again, in my neverending assembler project)
and found that they can dramatically improve program performance and sometimes even provide away to write "generic" code much faster.

Kobi.
 
 

Recent GIDBlogNot selected for officer school by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Printing problems--->ARG! toddm123 .NET Forum 0 31-Mar-2005 12:51
printing format stacy12 C Programming Language 1 30-Mar-2005 01:14
printing binary search tree nkhambal C Programming Language 2 26-Mar-2005 03:01
problem printing output iamsodumb C++ Forum 4 10-Mar-2005 13:19
printing integers in graphics mode enggwaqas C Programming Language 4 04-Oct-2004 20:47

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 06:33.


vBulletin, Copyright © 2000 - 2010, Jelsoft Enterprises Ltd.