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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T10:50:16+00:00 2026-06-15T10:50:16+00:00

I have a code distance = (double**)malloc(city_count*sizeof(double*)); for(i=0; i<city_count; i++) { distance[i] = (double*)malloc(city_count*sizeof(double));

  • 0

I have a code

distance = (double**)malloc(city_count*sizeof(double*));
for(i=0; i<city_count; i++) 
{
distance[i] = (double*)malloc(city_count*sizeof(double));
}

for(i=0; i<city_count; i++)
{
  for(j=0; j<city_count; j++) 
      {
         distance[i][j] = 1; // fscanf(fp, "%d", &tmp); distance[i][j] = tmp; EDITED

  }
}

Then I debug it in Visual Studio it works just fine. But on a real cluster it always filled with zeros. Can anybody help me?

Problem with assignment to matrix, not in reading files.

  • 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-15T10:50:17+00:00Added an answer on June 15, 2026 at 10:50 am

    But on a real cluster it always filled with zeros.

    for(i=0; i<city_count; i++)
    {
        for(j=0; j<city_count; j++) 
        {
            fscanf(fp, "%d", &tmp);
    

    Update

    With your simplified problem statement (thanks for that) it pretty much leaves checking the pointer values returned by malloc to make sure they’re not NULL (which would be very surprising unless city_count is really large.)

    Old Update

    Doh! I just noticed. %d reads an int which doesn’t match the type of &tmp. Should be:

            fscanf(fp, "%lf", &tmp);
    

    fscanf isn’t typesafe so this type of mismatch usually causes a problem.

    Post Facto Edit

    And make sure you’re not making the same mistake passing "%d" to printf. 😉

    End Update

    Make sure city_count isn’t 0.

    Check fscanf‘s return value (and the value of tmp). Are you sure this file read is succeeding? From the docs at cplusplus.com

    On success, the function returns the number of items of the argument list successfully filled. This count can match the expected number of items or be less (even zero) due to a matching failure, a reading error, or the reach of the end-of-file.

    If a reading error happens or the end-of-file is reached while reading, the proper indicator is set (feof or ferror). And, if either happens before any data could be successfully read, EOF is returned.

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

Sidebar

Related Questions

We have some code which sorts a list of addresses based on the distance
I have the following code; http://pastebin.com/Wf598D2E But I can't get distance value to #result
In PHP, I have the following code for calculating the distance between two locations:
I have the following code that I use to compute the distance between two
I have a function that calculates the distance between two GPS coordinates. I then
In my code I have to do a lot of distance calculation between pairs
I have code that generates a List<string[]> variable but can't quite figure out how
I have code like this in my view model: function ChatListViewModel(chats) { var self
I have code which has a drop down list. And when a certain option
I have code that looks more or less like the code below but it

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.