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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T15:17:54+00:00 2026-05-26T15:17:54+00:00

I get a strange behavior when I compile the same program in Release in

  • 0

I get a strange behavior when I compile the same program in Release in VS2010. If I run the program from cmd.exe multiple times, the results become gibberish. However, if I run the program in Debug, the result is always the same.

Starting a new command prompt makes the program give out the right outputs again.

Any idea of what might be causing this?

Screenshot of the command prompt

Edit : The code :

int main(int argc, char* argv[])
{
    int* R;
    int capacity;

    if (argc < 2)
    {
        cerr << "Veuillez entrer le chemin du fichier d'entree" << endl;
        return 1;
    }

    vector<BTS> stations;
    LoadFromFile(argv[1], stations, capacity);

    int count = 1;
    if (argc == 3)
    {
        count = atoi(argv[2]);
    }

    clock_t startClock = clock();

    R = new int[capacity+1];
    for(int j = 0; j < count; j++)
    {
        memset(R, 0, capacity + 1);

        for(unsigned int i=0; i < stations.size(); i++)
        {
            for(int j=capacity; j >= 0; j--)
            {
                if(j-stations[i].getNumberOfSubscribers() >= 0)
                {
                    R[j] = max(stations[i].getRevenue() + R[j-stations[i].getNumberOfSubscribers()], R[j]);
                }
            }
        }
    }

    // Print the results
    cout << "Value : " << R[capacity] << endl;
    cout << "Temps total : " << ((float)(clock() - startClock) / (float)CLOCKS_PER_SEC) << " s" << endl;

    delete[] R;

    return 0;
}

void LoadFromFile(std::string filePath, std::vector<BTS>& baseStations, int& capacity)
{
    fstream source(filePath);

    int numberOfStation;
    source >> numberOfStation;
    source >> capacity;

    for (int i = 0; i < numberOfStation; i++)
    {
        int index, revenue, numberOfSuscribers;
        source >> index;
        source >> revenue;
        source >> numberOfSuscribers;

        BTS station = BTS(index, revenue, numberOfSuscribers);

        baseStations.push_back(station);
    }

    source.close();
}

The rest of the code is only getters. Now for the file I give as input :

10 25
    1     7     6
    2     4     4
    3     7     6
    4     2     1
    5     7     8
    6     9    10
    7     4     5
    8    10    10
    9     1     1
   10    10    10
  • 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-26T15:17:55+00:00Added an answer on May 26, 2026 at 3:17 pm

    Your memset isn’t correct. You forgot the sizeof():

    memset(R, 0, capacity + 1);
    

    should be:

    memset(R, 0, (capacity + 1) * sizeof(int));
    

    Since you didn’t zero all of R, the upper parts of it are undefined and are giving you junk data.

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

Sidebar

Related Questions

When I run STLport on Darwin I get a strange crash. (Haven't seen it
I get some strange behavior when inserting values into a map: I always insert
I've come across some strange behavior trying to get files that start with a
I'm witnessing a strange behavior in a .net program : Console.WriteLine(Int64.MaxValue.ToString()); // displays 9223372036854775807,
When I create a new project, I get a strange behavior for unhandled exceptions.
We're seeing a strange behavior where things that get cached (in the IE/wininet cache)
I am getting some strange behavior from list view. I need to change background
This behavior is strange because I could not get the segfault if the shared
I get a strange behavior when declaring an object with the logical OR. my_var
This time I get a strange behavior with NSFetchedResultsController. I create a fetchRequest like

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.