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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T14:54:58+00:00 2026-05-20T14:54:58+00:00

I’m new to pointers and so am having a bit of difficulty. I do

  • 0

I’m new to pointers and so am having a bit of difficulty. I do believe though that the solution to this should be easy for you experts. The problem is in the code.

 // flags is an array of data that I create, manipulate, but now having trouble accessing elsewhere. 
int *flags = (int *) malloc(1* sizeof(int)); // let us start with 1 and then add more within the method. This should continue until we have all the flags we want.  
int number_of_flags = event_extractor(vocal_data, size, flags);

// I want to use flags here, but it doesn't work 

place_effects_on_events(vocal_data, flags, number_of_flags , events_with_effects);

THE OTHER METHODS:

int event_extractor (int *audio_samples, unsigned int size_of_audio, int *flags)
{

int number_of_flags = apply_threshold (lopass_samples, length, &flags);

    // the data prints absolutely correctly here.   
for (int i = 0; i < number_of_flags; i++) {
    printf("FLAG %i  -- %d \n", i, flags[i]);
}
}





 int apply_threshold (int *audio_samples, unsigned int size_of_audio, int **event_flags)
 {


int flag = 0; // this will be the number of flags that I have 
bool run = true; // this will make sure that a minimum amount of time passes before I grab another flag. It's a guard.
int counter = 0; // this is the counter for the above guard. 




int threshold = calculate_threshold_value(audio_samples, size_of_audio);



int length = (int)size_of_audio;




for (int i = 0; i < length-1; i++) 
{

    if (audio_samples[i] > threshold  && run) 
    {


        *event_flags = (int*)realloc(*event_flags, sizeof(int) * (flag + 1));
        (*event_flags)[flag] = i;

        flag++;
        run = false;


    }   

    if (!run) {
        counter++;
        if (counter > 20100) { // hardcode minimum size for now. 
            counter = 0;
            run=true;
        }
    }



}


for (int i = 0; i <10 ; i++) {
    printf("VOCAL SAMPLE %i  %i \n", i-5,audio_samples[*event_flags[1]+i-5] );
}

return flag;

}

THE PROBLEM IS HERE

 void place_effects_on_events (int *vocal_samples, int *flags, int number_of_flags ,int *events_with_effects)
 {


// here the data does not print correctly 
for (int i = 0; i < number_of_flags; i++) {
    printf("FLAG %i  -- %d\n", i,  flags[i]);
}
  • 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-20T14:54:59+00:00Added an answer on May 20, 2026 at 2:54 pm

    You should pass a pointer to flags to event_extractor:

    int number_of_flags = event_extractor(vocal_data, size, &flags);
    

    and change its prototype to

    int event_extractor (int *audio_samples, unsigned int size_of_audio, int **flags)
    

    Otherwise, flags itself is never updated and still points to the first malloced memory area. Since this memory area no longer exists at this time, accessing its contents will cause undefined results.

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

Sidebar

Related Questions

No related questions found

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.