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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T07:06:41+00:00 2026-05-26T07:06:41+00:00

Might someone explain why the atoi function doesn’t work for nmubers with more than

  • 0

Might someone explain why the atoi function doesn’t work for nmubers with more than 9 digits?

For example:

When I enter: 123456789,
The program program returns: 123456789,

However,when I enter: 12345678901
the program returns: -519403114...

int main ()
{
    int i;
    char szinput [256];
    printf ("Enter a Card Number:");
    fgets(szinput,256,stdin);
    i=atoi(szinput);
    printf("%d\n",i);
    getch();
    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. Editorial Team
    Editorial Team
    2026-05-26T07:06:41+00:00Added an answer on May 26, 2026 at 7:06 am

    Don’t use atoi(), or any of the atoi*() functions, if you care about error handling. These functions provide no way of detecting errors; neither atoi(99999999999999999999) nor atoi("foo") has any way to tell you that there was a problem. (I think that one or both of those cases actually has undefined behavior, but I’d have to check to be sure.)

    The strto*() functions are a little tricky to use, but they can reliably tell you whether a string represents a valid number, whether it’s in range, and what its value is. (You have to deal with errno to get full checking.)

    If you just want an int value, you can use strtol() (which, after error checking, gives you a long result) and convert it to int after also checking that the result is in the representable range of int (see INT_MIN and INT_MAX in <limits.h>). strtoul() gives you an unsigned long result. strtoll() and strtoull() are for long long and unsigned long long respectively; they’re new in C99, and your compiler implementation might not support them (though most non-Microsoft implementations probably do).

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

Sidebar

Related Questions

I was hoping someone might help with a function that given two parameters: @param
Can someone briefly explain on HOW and WHEN to use a ThreadFactory? An example
I know that __builtin__ sorted() function works on any iterable. But can someone explain
Can someone please explain (what might be my perceived) disparity in errors in the
Could someone explain what might happen if you don't Dispose some IDisposable entity (by
I wondered if someone might have some insight into this. jqGrid is quite happy
I'm having some strange drawing artefacts that I'm hoping someone might be able to
Can someone give me some info/background info on how I might go about writing
I'm concerned that this might be working on an NP-Complete problem. I'm hoping someone
Could someone please explain the difference in how the 2 snippets of code are

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.