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

Ask A Question

Stats

  • Questions 120k
  • Answers 120k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer No. Out of the box SQL Server will not backup… May 12, 2026 at 12:15 am
  • Editorial Team
    Editorial Team added an answer You can get TestDriven.NET. This add-in for Visual Studio supports… May 12, 2026 at 12:15 am
  • Editorial Team
    Editorial Team added an answer I try to follow the The Rule of Least Power… May 12, 2026 at 12:15 am

Related Questions

I am working on a project where I need to deal at the byte
I am working on a self project, where I am trying to convert a
I am working on a project where I produce an aluminium extrusion cutting list.
From what I understand there is no SMTP server in IIS on Vista. I

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.