Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6719681
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T09:07:17+00:00 2026-05-26T09:07:17+00:00

I am new in C programming language and have an (if statement) and need

  • 0

I am new in C programming language and have an (if statement) and need to transfer it into switch statement.
My problem is that I have a field named (node_kind) of char* type and I compare it’s content in the if statement using (strcmp) but I don’t know how to do that in the switch statement.
Would you plz tell me how ?
Here is a short quote of my program

if (strcmp(node->node_kind, "VAR_TOKEN_e") == 0) 
    job = visitor->visitjob_VAR_TOKEN; 
if (strcmp(node->node_kind, "INT_e") == 0) 
    job = visitor->visitjob_int; 
if (strcmp(node->node_kind, "BOOL_e") == 0) 
    job = visitor->visitjob_bool; 
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T09:07:18+00:00Added an answer on May 26, 2026 at 9:07 am

    You can use gperf (website) to generate a perfect hash, which turns strings into integers. You’ll have something like this:

    In your header file:

    enum {
        STR_VAR_TOKEN_e,
        STR_INT_e,
        STR_BOOL_e
    };
    int get_index(char *str);
    

    In your gperf file:

    struct entry;
    #include <string.h>
    #include "header.h"
    struct entry { char *name; int value; };
    %language=ANSI-C
    %struct-type
    %%
    VAR_TOKEN_e, STR_VAR_TOKEN_e
    INT_e, STR_INT_e
    BOOL_e, STR_BOOL_e
    %%
    int get_index(char *str)
    {
        struct entry *e = in_word_set(str, strlen(str));
        return e ? e->value : -1;
    }
    

    In your switch statement:

    switch (get_index(node->node_kind)) {
    case STR_VAR_TOKEN_e: ...
    ...
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I always believed that when starting to learn a new programming language programmer must
Which programming language is it easier to support developers in (namely developers that have
I have an interesting idea for a new programming language. It's based on a
I'm new to using the C#/.NET programming Language and I have created a DataGridView
I want to learn a new programming language. I have in mind stuff like
Suppose I have designed a new programming language for one of the managed code
It seems that most new programming languages that have appeared in the last 20
Ruby (and the Rails framework) is the first new programming language that I've learned
i been thinking of a new programming language. Before trying to implement it i
What features could be added to a new programming language to make it more

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.