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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T23:02:35+00:00 2026-05-24T23:02:35+00:00

In Objective-C, how can I define a C array of ‘unknown size’ as an

  • 0

In Objective-C, how can I define a C array of ‘unknown size’ as an instance variable, and later populate the array?

(Background) : I have a class in Objective-C which handles loading game data. The data is stored in an array of C structs, contained in an external datafile. I can load in the array and access it, but I need it to be accessible throughout the class. What I’m trying to do is declare an ’empty’ array in my instance variables and then (when loaded) point this empty array or replace it with the one I’ve loaded in.

This is how I’m loading in my data…

FILE *fptr = NULL;
fptr = fopen([path cStringUsingEncoding:NSUTF8StringEncoding], "r");

// Create an empty array of structs for the input file with known size
frame2d newAnimationData[28];

// Read in array of structs
fread(&newAnimationData, sizeof(newAnimationData), 1, fptr);
fclose(fptr);

So this code works fine to recreate my array of frame2d structs – I just need to know how I can use this as an instance variable.

Any help is appreciated,
thanks.

  • 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-24T23:02:37+00:00Added an answer on May 24, 2026 at 11:02 pm

    Declare it as frame2d*, then figure out how big it needs to be at runtime and initialize it with calloc(numberOfFrame2Ds, sizeof(frame2d));

    Or use an NSMutableArray and wrap the structs in NSValue objects if resizing and safety at runtime is more important than efficiency.

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

Sidebar

Related Questions

I know you can define a global variable in Objective-C by using extern, but
Is there a way in objective C that I can define a static int
A class can be extended in Objective C using a category such as: @interface
I would like to define the following function in Objective-C. I have provided pseudo-code
On OS X, does Objective-C compile to native code or byte-code? Can Objective-C programs
Objective : Make a progress bar where users can check how much of a
How can I execute a terminal command (like grep ) from my Objective-C Cocoa
Can anyone recommend a C or Objective-C library for HTML parsing? It needs to
You can use a standard dot notation or a method call in Objective-C to
Can anyone explain the differences between Protocols and Categories in Objective-C? When do you

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.