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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T21:40:32+00:00 2026-05-11T21:40:32+00:00

Can we convert an NSArray to a C array? If not what alternatives, are

  • 0

Can we convert an NSArray to a C array?

If not what alternatives, are there? Suppose I need to feed the C array to OpenGL functions where the C array contains vertex pointers read from plist files.

  • 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-11T21:40:32+00:00Added an answer on May 11, 2026 at 9:40 pm

    The answer depends on the nature of the C-array.

    If you need to populate an array of primitive values and of known length, you could do something like this:

    NSArray* nsArray = [NSArray arrayWithObjects:[NSNumber numberWithInt:1],
                                                 [NSNumber numberWithInt:2],
                                                 nil];
    int cArray[2];
    
    // Fill C-array with ints
    int count = [nsArray count];
    
    for (int i = 0; i < count; ++i) {
        cArray[i] = [[nsArray objectAtIndex:i] intValue];
    }
    
    // Do stuff with the C-array
    NSLog(@"%d %d", cArray[0], cArray[1]);
    

    Here’s an example where we want to create a new C-array from an NSArray, keeping the array items as Obj-C objects:

    NSArray* nsArray = [NSArray arrayWithObjects:@"First", @"Second", nil];
    
    // Make a C-array
    int count = [nsArray count];
    NSString** cArray = malloc(sizeof(NSString*) * count);
    
    for (int i = 0; i < count; ++i) {
        cArray[i] = [nsArray objectAtIndex:i];
        [cArray[i] retain];    // C-arrays don't automatically retain contents
    }
    
    // Do stuff with the C-array
    for (int i = 0; i < count; ++i) {
        NSLog(cArray[i]);
    }
    
    // Free the C-array's memory
    for (int i = 0; i < count; ++i) {
        [cArray[i] release];
    }
    free(cArray);
    

    Or, you might want to nil-terminate the array instead of passing its length around:

    // Make a nil-terminated C-array
    int count = [nsArray count];
    NSString** cArray = malloc(sizeof(NSString*) * (count + 1));
    
    for (int i = 0; i < count; ++i) {
        cArray[i] = [nsArray objectAtIndex:i];
        [cArray[i] retain];    // C-arrays don't automatically retain contents
    }
    
    cArray[count] = nil;
    
    // Do stuff with the C-array
    for (NSString** item = cArray; *item; ++item) {
        NSLog(*item);
    }
    
    // Free the C-array's memory
    for (NSString** item = cArray; *item; ++item) {
        [*item release];
    }
    free(cArray);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 119k
  • Answers 119k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer By the nature of MVC, you can't access any UI… May 11, 2026 at 11:56 pm
  • Editorial Team
    Editorial Team added an answer Ok, the problem is with my Address Entity object, I… May 11, 2026 at 11:56 pm
  • Editorial Team
    Editorial Team added an answer Why don't you use an array or a vector rather… May 11, 2026 at 11:56 pm

Related Questions

How can we convert data displayed in a reportviewer to an xml file?
Quaternions are arguably an appropriate choice for representing object rotations internally. They are simple
Is there any way to convert a bmp image to jpg/png without losing the
Is there any way we can convert text to speech in an iPhone app?

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.