Jump to content

Printing a special type?

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
2 replies to this topic

#1
blernblan

blernblan

    Newbie

  • Members
  • Pip
  • 9 posts
Hey guys, I'm trying simply to print the property called "NodeKind" within my syntax tree. It's declared as such:


typedef enum {VarK,IdK,OpK,ConstK,ComK} NodeKind;


Every node in my tree has a "kind" pointer. But when I try to use the following print statement, nothing is printed:


printf("%s", ptree->kind);


Is there a special way to print out special types like this? Thanks to anyone for any help!

#2
WingedPanther

WingedPanther

    A spammer's worst nightmare

  • Moderators
  • 16,831 posts
An enum is a list of integer values, not a list of strings.
Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

#3
dargueta

dargueta

    Writes binary right handed and hex left handed

  • Moderators
  • 4,715 posts
You're lucky that didn't segfault on you. Since enums start with 0 and increase sequentially (unless you change it), you can create a static array of strings and use the value of the type as an index into the array.