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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T13:47:02+00:00 2026-06-17T13:47:02+00:00

I have a assignment where I need to take a 7 digit input (a

  • 0

I have a assignment where I need to take a 7 digit input (a phone number) and check if it’s found in the digits of pi. The digits of pi are stored in a supplied space separated text file. It seems reasonably straightforward: break the input into an array, read the digits of pi into an array, and check if a match is found. Long story short, I got the program working to my satisfaction. We were supplied text documents with the digits of pi in multiples of 10, 100, and so on up to 1 million digits. My program works up to 100,000 digits. But for whatever reason, on the 1 million digit file, it crashes with a generic windows error. I have no information on why it crashes and no error message is given (except the generic “a problem caused this program to stop working” message).

Noting that limits on the assignment state I cannot use any object-orientated code except for cin, cout, and the file stream objects (this limitation is because we’ve yet to get into classes and they don’t want us using functions without knowing how they work).

Anyway, I’m looking for insight as to why the program is crashing. I’m using long ints on every variable that should need them (including counters and function returns), which should be sufficient, since they can go up to roughly 2 billion and there should not be any numbers larger than a million here.

Thanks for any help. I’ve been at this the past few hours with no success.

const long int numberOfDigits = 1000000;
int digitsOfPi[numberOfDigits];
  • 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-06-17T13:47:03+00:00Added an answer on June 17, 2026 at 1:47 pm
    int digitsOfPi[numberOfDigits];
    

    The stack does not have enough room to hold such a large array. The stack is where automatic variables (AKA local variables) are stored. Memory is automatically allocated for local variables when execution enters a function and is freed when the function returns. The stack is great because of this automatic memory management, but one restriction is that its size is limited.

    Large objects should go on the heap.1 The heap is a gigantic pool of memory from which you can allocate pieces dynamically whenever you like. The difference between the heap and the stack is that you’re responsible for allocating and freeing heap memory. It does not get automatically freed for you.

    To allocate memory on the heap in C++, use the new operator, with each new having a corresponding delete to free the memory once it’s no longer needed. (Or in our case, we use new[] and delete[] since we’re dealing with an array.)

    // Allocate memory on the heap.
    int *digitsOfPi = new int[numberOfDigits];
    
    // Use it.
    
    // Then free it.
    delete[] digitsOfPi;
    
    // Or better yet, once you're allowed to use the STL...
    std::vector<int> digitsOfPi;
    

    The larger question, though, is why you need to read all the digits of π into memory at once. A better design, though trickier to code, would only need a fixed O(1) amount of memory—say, 7 digits at a time.

    See also

    • What and where are the stack and heap?

    1 You could explore your compiler’s options to increase the stack size, but that’s not the right solution.

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

Sidebar

Related Questions

I have a homework assignment where I need to take input from a file
I have an assignment where I need to read a certain number of Foo
Hi I have a homework assignment where I need to implement an intersection of
Hello is have a question for a school assignment i need to : Read
I have a question about a school assignment I need to do it in
I have an assignment where we need to write a (very simplified) multithreaded compression
I need to implement a chess game for a school assignment, and you have
I have an assignment in my java class that i need to recursively print
I have an assignment and i need working code. Before i start i want
I have an assignment where I need to read a text file and then

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.