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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T18:29:02+00:00 2026-06-13T18:29:02+00:00

I have a program and in there, I dynamically allocate memory by using malloc;

  • 0

I have a program and in there, I dynamically allocate memory by using malloc; here is the important part:

unsigned int *hours;
unsigned int *minutes;
hours = (unsigned int *) malloc(n * sizeof(*hours));
minutes = (unsigned int *) malloc(n * sizeof(*minutes));

After this, I have a for loop, that loops n times; each time it reads time and stores hours at hours[i] and minutes at minutes[i]; for (i = 0; i < n; i++)

I read n before allocation using :

scanf(%d, &n);

Next, I have function, that takes 3 parameters, it looks like this:

void convertToMinutes(unsigned int *hours[],unsigned int *minutes[],int n)
{
     unsigned int i;
     for (i = 0; i < n; i++)
     {
         *minutes[i] =*hours[i]*60 + *minutes[i];
     }
}

This is part that causes program to crash. I’m using Dr. Memory to see what happens, here is dump:

Error #1: UNADDRESSABLE ACCESS: reading 0x00000005-0x00000009 4 byte(s)
# 0 convertToMinutes    
# 1 main                
Note: @0:00:11.408 in thread 1740
Note: instruction: mov    (%eax) -> %ecx

As you can see, it tries to read address at 0x00000005, which causes Windows to shut it down.

So before calling this function, I looked at addresses of hours and minutes arrays and here is what I found:

for n = 3
hours base 10948584
hours+1    10948588
hours+2    19848592
minutes base 10948608
minutes+1    10948612
minutes+2    10948616

(Addresses are converted to int)

I’m lost. I have no idea what is wrong. Pointers are new to me (I’ve been using them for few days) and I have no idea why it suddenly tries to read at forbidden address. What am I doing wrong?

  • 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-13T18:29:04+00:00Added an answer on June 13, 2026 at 6:29 pm

    This function signature takes arguments that are arrays of pointer to unsigned int

    void convertToMinutes(unsigned int *hours[],unsigned int *minutes[],int n)
    

    but your arrays are arrays of unsigned int not unsigned int *. Try changing it to

     void convertToMinutes(unsigned int hours[],unsigned int minutes[],int n)
    

    or (since array arguments will decay to a pointer anyway) even

    void convertToMinutes(unsigned int* hours,unsigned int* minutes,int n)
    

    The inside the function remove the dereferencing and change to:

     for (i = 0; i < n; i++)
     {
         minutes[i] = hours[i]*60 + minutes[i];
     }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

My program looks like this! I want to have the bottom part dynamically load
I have a program wherein there are multiple tabs added dynamically to a TabControl
I have a CC 1.1 card and my program entails me to dynamically allocate
I have an ANSI C program that dynamically loads a .so file using dlopen()
Is there a way to read the web service methods dynamically using a program?
I have a program, and in that program there is some variables (username and
I have a program where there is a master/slave setup, and I have some
I have a program that outputs a table, and I was wondering if there
I have a program that creates a JFrame and makes it visible. Is there
I have a python program that must work on Windows and Linux. There are

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.