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 915919
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T17:58:03+00:00 2026-05-15T17:58:03+00:00

So as we all probably know, the atoi converts a char to a number.

  • 0

So as we all probably know, the atoi converts a char to a number. But, what do you do if you only want one of the array elements instead of the whole array?

Please look at the following:

for (h = 0; h < 5; h++)
{
    num[h] = atoi(temp[h]);
}

Assume that num is an array of type int and that temp is and array of type char. This gives me one of those annoying conversion problems:

Invalid conversion from ‘char’ to ‘const char *’

Any suggestions on how to convert a single element of a char array to an int using atoi?

  • 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-15T17:58:03+00:00Added an answer on May 15, 2026 at 5:58 pm

    If you only want to convert a single character you don’t need to use atoi():

    if (temp[h] >= '0' && temp[h] <= '9')
    {
        num[h] = temp[h] - '0';
    }
    else
    {
        // handle error:  character was not a digit
    }
    

    In C, the value of each digit is one greater than the value of the previous digit, so this is guaranteed to work.

    The reason that atoi() does not work is because it takes a const char* as its argument, not a char. That pointer has to point to a null terminated string.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Morning y'all This is probably an easy one but I barely got any sleep
This is probably pretty simple. I want to select all elements of a given
I have the following code.. and I know it's probably all wrong, but I
first of all i would like to say i know its probably an easy
First of all there is probably a question like this already but i couldn't
I am using ASP.Net MVC but this probably applies to all MVC patterns in
Sorry this is probably super basic. But in all my javabean examples, I've not
My problem has probably been asked, but all the ones I've been searching for
You probably all know the famous virtual zippo app. I thought of making such
I know you all probably thinking that on() is the solution and I hope

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.