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

  • SEARCH
  • Home
  • 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 162791
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T11:27:13+00:00 2026-05-11T11:27:13+00:00

I am working on a project where I can to convert a api digit

  • 0

I am working on a project where I can to convert a api digit to a char. I have used an array of string pointers to get the conversion. However, I want to return just a single ch, as my api that I am using will only accept a char. So ap_five will return ‘5’. But I want to five to be a single char ‘5’.

I thought maybe I could cast to a char in the return. However, I just get rubbish.

I am sure there is other ways to solve this, how I am just wondering how can I solve with my present program.

char *digits_conversion[][2]= {     {'ap_zero', '0'},     {'ap_one', '1'},     {'ap_two', '2'},     {'ap_three', '3'},     {'ap_four', '4'},     {'ap_five', '5'},     {'ap_six', '6'},     {'ap_seven', '7'},     {'ap_eight', '8'},     {'ap_nine', '9'},     {'ap_star', '*'},     {'ap_hash', '#'},     {NULL, NULL} };  char convert_to_char(const char *digit) {     int i = 0;     for(i = 0; *digits_conversion[i][1]; i++)     {         if(strcmp(digits_conversion[i][0], digit) == 0)         {             return (char) digits_conversion[i][1];         }     }      return '\0'; }  int main(void) {     char ch;      ch = convert_to_char('ap_five');      printf('Converted digit: %c\n', ch);      return 0; } 
  • 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. 2026-05-11T11:27:14+00:00Added an answer on May 11, 2026 at 11:27 am

    The simplest fix to your existing code is just to change:

    return (char) digits_conversion[i][1]; 

    into

    return digits_conversion[i][1][0]; 

    However, you might find that changing digits_conversion into an array of structures will give you code that is easier to understand and maintain. For example:

    struct digit_mapping {     char *api_name;     char digit; }; struct digit_mapping conversion_table[] = {     { 'ap_zero', '0' },     {'ap_one', '1'},     {'ap_two', '2'},     {'ap_three', '3'},     {'ap_four', '4'},     {'ap_five', '5'},     {'ap_six', '6'},     {'ap_seven', '7'},     {'ap_eight', '8'},     {'ap_nine', '9'},     {'ap_star', '*'},     {'ap_hash', '#'},     {NULL, '\0'} };  char convert_to_char(const char *digit) {     int i = 0;     for(i = 0; conversion_table[i].digit; i++)     {             if(strcmp(conversion_table[i].api_name, digit) == 0)             {                     return conversion_table[i].digit;             }     }      return '\0'; }  int main(void) {     char ch;      ch = convert_to_char('ap_five');      printf('Converted digit: %c\n', ch);      return 0; } 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've been working on a project that can't be described as 'small' anymore (40+
I'm working on a project for school, and I'm implementing a tool which can
I'm working in a C++ unmanaged project. I need to know how can I
I'm currently working on project with Haskell, and have found myself some trouble. I'm
I am working a project that does not have a trunk / branches /
Working on a project at the moment and we have to implement soft deletion
Ok, i'm a bit confused. I am working on a project that have to
I'm working on this project and I have a large number of services to
I am working a project where I need to generate a series of classes
I am working on project in Linux which involves 1) Static Lib in C++

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.