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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T23:30:49+00:00 2026-05-23T23:30:49+00:00

i obtained a double value with decimal part as 0 from calculations and then

  • 0

i obtained a double value with decimal part as 0 from calculations and then want to convert this value into char array consisting of the digits as elements(using ascii codes) and then return it…i wrote the following code for it…

char* as_string(double a,char* ptr)
{
  int digits=0;
  for(int i=1;;i++)
  {if(static_cast<int>(a/pow(10.0,i))==0)
  {digits=i;
  break;}
  }

 char b[digits];
 for(int i=digits-1;i>=0;i--)
 {
 b[digits-1-i]=static_cast<int>(a/pow(10.0,i))+48;
 a=a-((b[digits-1-i]-48)*pow(10.0,i));
 }

 strncpy(ptr,b,digits);
 return ptr;
}     

everything went on all right…there was no syntax error but at runtime the prog was aboted each time…after some scrutiny i found that error is taking place around pointer ptr and strcpy statements(as the array b was successfully tested as filled with the digits )…can anyone plz. point out the error?

  • 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-23T23:30:50+00:00Added an answer on May 23, 2026 at 11:30 pm

    You should ask yourself the Question:

    Is ptr pointing to a memory location big enough to hold digits?
    I don’t think so.

    The problem is you are passing a pointer ptr to the function but you don’t know before hand how much memory is needed to be allocated to ptr.

    You can have two options:

    You can guess the maximum value possible allocate the same to ptr using new or on stack & then pass ptr to the function

    Or

    You allocate memory to ptr inside the function using new where you know exactly how much memory is needed. Note that to do so you will have to pass ptr as a double pointer.

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

Sidebar

Related Questions

I have a dataset obtained from MySQL that goes like this: Array ( [0]
This has to be obtained from a remote machine. The following query works not
I have obtained the crosshair cursor from NSCursor crosshairCursor. Then, how can i change
I have obtained the 4sq checkin id from twitter streaming api and I want
I have a list of recipes obtained from a database that looks like this:
I'm trying to display data from an array of objects obtained using another company's
I obtained the data from the server using ajax like this: (EDITED) $(document).ready(function() {
From IDispatch::GetTypeInfoCount The return value obtained from the returned HRESULT is one of the
I have a DataTable obtained from a SQL DataBase, like this: using (SqlCommand cmd
A typical code fragment obtained from the YouTube embed feature looks like this: <object

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.