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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T08:32:02+00:00 2026-06-18T08:32:02+00:00

I am working on a project for school and I have managed to figure

  • 0

I am working on a project for school and I have managed to figure out a work around by doing something really clunky with my code. I have a structure that holds multiple fields, and I am trying to access the following field (as it is declared in the struct named current_event).

int *number_of_couples;

and later down into the program I call this value so I can dynamically allocate an array based on this *number_of_couples field. Essentially I am trying to use this as a “length” operator as C does not have (good) solution.

Before I was trying to implement the following code:

int *permutable_array;
permutable_array = malloc((current_event->number_of_couples) * sizeof(int)); //Line 91
if(permutable_array == NULL){
    panic("permutable_array"); //Ensures that Malloc was successful. 
}

which would in turn throw the following error:
Line 91: error: invalid operands to binary * (have ‘int *’ and ‘unsigned int’)

I have made a very sloppy work around because at this point I just want to get the program working (hour three of pure programming! rock on!). So I implemented:

int *permutable_array;
int avoid_my_bug = (int) current_event->number_of_couples;
permutable_array = malloc(avoid_my_bug * sizeof(int));
if(permutable_array == NULL){
    panic("permutable_array");
}

Which works. Now I somewhat understand the error that it is telling me. I suspect it has something to do with the fact that I stored the value of number_of_couples as a pointer within current_event, which is also a pointer. So really if the value of number_of_couples is 4, the path the program makes to get to that value is:

ptr_to_current_event -> ptr_to_number_of_couples -> 4

I can use my sloppy work-around, but it is obvious that I am doing it to avoid a bug. I would rather learn why the code will not compile. I also tried doing:

permutable_array = malloc((*current_event->number_of_couples) * sizeof(int)); //Line 91

which should have dereferenced the pointer returned by current_event->number_of_couples, however it crashes. Any solutions?

*EDIT*
It is initialized by the following line of code:

fscanf(input_file, "%i", &current_event->number_of_couples);

and is referenced at least three times (there is a valid int value stored in it) by the program before reaching my code. Remember, the second bit works, therefore it is definitely initialized.

  • 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-18T08:32:03+00:00Added an answer on June 18, 2026 at 8:32 am

    You shouldn’t be storing integer values inside pointers. Pointers are made to point at things, you should rarely need to convert a pointer to an integer type. If you do you should use either the uintptr_t or intptr_t types.

    You should either dereference the pointer (assuming it is pointing at a valid int) or change the type of number_of_couples so that it is not a pointer. If you leave it as a pointer, you must ensure it is pointing to a valid int object before trying to dereference it, but based on your usage and context above, it doesn’t need to be a pointer.

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

Sidebar

Related Questions

I am working on a school project (if you couldn't figure that out just
In a school project, I have implemented a working syncadapter for syncing contacts with
I'm working with a Ruby project for school, and have sadly not been able
My team working on a php/MySQL website for a school project. I have a
I am working a school project to implement a Huffman code on text. The
Set up and Explanation : I'm working on a project for school, and have
I have been working on a school project for months now and I'm almost
I have been working on a project for school. Basically you have to make
I'm working on a school project where we have to create a virtual smartphone,
I'm working on a school project now, do you have any idea on how

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.