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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T03:04:39+00:00 2026-05-31T03:04:39+00:00

I am trying to convert some chars into numeric type, but some of them

  • 0

I am trying to convert some chars into numeric type, but some of them may not be null-terminated strings. So are strtol, strtoll, strtod safe for those strings that aren’t null-terminated?

  • 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-31T03:04:40+00:00Added an answer on May 31, 2026 at 3:04 am

    No.

    If a character array is not terminated by a null character, then it’s not a string. If any of the strto*() functions are passed an argument that doesn’t point to a string, the behavior is undefined.

    Referring to the latest draft of the 2011 ISO C standard:

    7.1.1 Definition of terms:

    A string is a contiguous sequence of characters terminated by and
    including the first null character.

    7.1.4 Use of library functions:

    If an argument to a function has an invalid value (such as a value
    outside the domain of the function, or a pointer outside the address
    space of the program, or a null pointer, or a pointer to
    non-modifiable storage when the corresponding parameter is not
    const-qualified) or a type (after promotion) not expected by a
    function with variable number of arguments, the behavior is undefined.

    7.22.1.3 The strtod, strtof, and strtold functions:

    The strtod, strtof, and strtold functions convert the initial portion of the string pointed to by nptr to double, float, and long double representation, respectively.

    (emphasis added)

    So an argument that doesn’t point to a string is outside the domain of the function.

    You’re likely to get away with it if the array contains something like { '1', '2', '3', 'x', 'y', 'z' }, since it doesn’t need to scan past the x that terminates the desired value, but the behavior is explicitly undefined.

    If you want to use these functions, you should, if necessary, copy your array into another buffer and explicitly null-terminate it yourself.

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

Sidebar

Related Questions

I'm trying to convert some simple .htaccess rewrites into web.config xml; all is well
I'm trying to convert some VB.net code into C# and having issues trying to
I am trying to convert an SVN repository to Mercurial, but I'm having some
I'm trying convert all special chars into HTML safe entities on their way into
Hi I am trying to split a string into an array of chars but
I have some C code that I'm trying to convert/wrap into a C++ class.
i am trying to convert array object into string but still it is returning
Background : I'm trying to convert some JavaScript code which uses the the Crossfilter
I am trying to convert some pre-existing html/JavaScript files to Flex. I tried making
I am trying to convert some ExtJS 3.3 to 4.0. In ExtJS 3.x I

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.