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

The Archive Base Latest Questions

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

see code, question after. #include <iostream> #include <cstdio> bool prime(unsigned long long num); int

  • 0

see code, question after.

#include <iostream>
#include <cstdio>

bool prime(unsigned long long num);

int main(){
unsigned long long temp;
unsigned long long max = 600851475143;
FILE * fptr;

try{
fptr = fopen("primes.txt","w");

#pragma omp parallel for
for(unsigned long long i = 2; i<max;i++){
    if(prime(i)){
        temp = i;
        fputs(i + ",",fptr);
        //int percent = (int)((float)i)/((float)max);
        //if(percent > 1 && (percent % 10 == 0)){
        //  std::cout << "Percent Complete: " << percent << std::endl;
        //}
    }
}
std::cout << temp << std::endl;
fclose(fptr);
}catch(...){
    std::cout << "Exception!" << std::endl;
}
return 0;
}

bool prime(unsigned long long num){
for(unsigned long long i = 2;i<num;i++){
    if(num%i == 0)
        return false;
}
return true;
}

@gw runtime failure:

runtime failure:

time failure:

me failure:

ailure:
:

tualQuery failed for %d bytes at address %pQuery failed for %d bytes at address %pery failed
for %d bytes at address %pfailed for %d bytes at address %p for %d bytes at address %pd
bytes at address %pbytes at address %pat address %pddress %press %ppnown pseudo relocation
protocol version %d.

udo relocation protocol version %d.

relocation protocol version %d.

location protocol version %d.

tion protocol version %d.

on protocol version %d.

rotocol version %d.

n %d.
.
Unknown pseudo relocation bit size %d.

nknown pseudo relocation bit size %d.

udo relocation bit size %d.

o relocation bit size %d.

cation bit size %d.

bit size %d.

Why is this runtime failure happening? I’m guessing it has something to do with unsigned long long but I have no idea. Also tried without the omp directive and still same problem.

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

    You made a mistake here:

    fputs(i + ",",fptr);
    

    fputs gets const char* as a first argument. You add integer value ‘i’ to a const char* “,” value. This expression i+”,” will point to an invalid memory block as soon as ‘i’ becomes larger then 0 since there is no overloaded operator ‘+’ in C++ which concatenates an integer with a const pointer to a char buffer

    You may use the sprintf function instead:

    char buf[256] = {0};
    sprintf(buf, "%d, ", i);
    

    or, simply fprintf which will put write the string directly to the file

    Also, I suggest you to close the file handle outside of the try{ .. }catch block. Otherwise, in case of exception, your file will not be closed at all

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

Sidebar

Related Questions

In my other question You can see code of my arr structure and PriorityQueue
in this question I posted you can see the originating code sample for this
I often see code like int hashCode(){ return a^b; } Why XOR?
My questions are divided into three parts Question 1 Consider the below code, #include
The code in c++ is as follows: #include<iostream> #include<string> #include<set> using namespace std; class
I'm trying to make a wrapper for some C-based sparse-matrix-handling code (see previous question
After writing a sample code for the question about converting between timezones , one
This is a follow-up question, but I'll include the code from before. I have
See code just bellow Our generic interface public interface Repository<INSTANCE_CLASS, INSTANCE_ID_CLASS> { void add(INSTANCE_CLASS
See code below: I want Page 1 to alert #testing... This works in C

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.