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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T03:46:06+00:00 2026-06-12T03:46:06+00:00

I’m trying to keep a float[] of my table row heights. I found a

  • 0

I’m trying to keep a float[] of my table row heights. I found a nice class for doing so here: http://forums.macnn.com/t/224809/nsmutablearray-vs-a-plain-c-array-for-storing-floats.

The problem is that once the C function (located in another file) gets called, the float that I passed in becomes 0. This happens every single time, regardless of the float value.

C function:

typedef struct
{
    float *array;
    int count;
} floatArray;

BOOL AddFloatToArray ( floatArray *farray, float newFloat )
{
    if ( farray->count > 0 )
    {
        // The array is already allocated, just enlarge it by one
        farray->array = realloc ( farray->array, ((farray->count + 1) * sizeof (float)) );

        // If there was an error, return NO
        if (farray->array == NULL)
            return NO;
    }
    else
    {
        // Allocate new array with the capacity for one float
        farray->array = (float *)malloc ( sizeof (float) );

        // If there was an error, return NO
        if (farray->array == NULL)
            return NO;
    }
    printf("Adding float to array %f\n", newFloat);
    farray->array[farray->count] = newFloat;
    farray->count += 1;
    printArrayContents(farray);
    return YES;
}

int printArrayContents( floatArray* farray)
{
    printf("Printing array contents\n");
    for(int j=0; j < farray->count; j++)
        printf("%f\n", farray->array[j]);


    return 0;
}

Called from:

    NSDictionary* review = [self.reviews objectAtIndex:indexPath.row];
    returnHeight = [ReviewCell cellHeightForReview:review];
    NSLog(@"Adding height to array: %0.0f", returnHeight);
    AddFloatToArray(heights, returnHeight);

Here’s what gets logged:

2012-09-28 11:46:12.787 iOS-app[1605:c07] -[ProductDetailViewController tableView:heightForRowAtIndexPath:] [Line 598] Adding height to array: 101
Adding float to array 0.000000
Printing array contents
0.000000
2012-09-28 11:46:12.788 iOS-app[1605:c07] -[ProductDetailViewController tableView:heightForRowAtIndexPath:] [Line 598] Adding height to array: 138
Adding float to array 0.000000
Printing array contents
0.000000
0.000000
2012-09-28 11:46:12.788 iOS-app[1605:c07] -[ProductDetailViewController tableView:heightForRowAtIndexPath:] [Line 598] Adding height to array: 122
Adding float to array 0.000000
Printing array contents
0.000000
0.000000
0.000000
2012-09-28 11:46:12.789 iOS-app[1605:c07] -[ProductDetailViewController tableView:heightForRowAtIndexPath:] [Line 598] Adding height to array: 139
Adding float to array 0.000000
Printing array contents
0.000000
0.000000
0.000000

How can I ensure that the correct value is actually inserted into the float[]?

  • 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-12T03:46:07+00:00Added an answer on June 12, 2026 at 3:46 am

    I didn’t declare the functions in the .h I was #importing. So everything compiled and ran, but the classes weren’t communicating correctly. You’d think that would raise a warning or error.

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

Sidebar

Related Questions

I am doing a simple coin flipping experiment for class that involves flipping a
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am trying to render a haml file in a javascript response like so:
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm trying to select an H1 element which is the second-child in its group

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.