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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T09:12:58+00:00 2026-06-03T09:12:58+00:00

Is there any easy way to convert an Objective-C holding class of NSStrings into

  • 0

Is there any easy way to convert an Objective-C holding class of NSStrings into parameters for a function accepting a variable list of char *? Specifically I have a function like:

-(void)someFunction:(NSSomething *) var

that I want to forward to a C function like

void someCFunction(char * var, …)

Is there an easy way to go about this?

  • 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-03T09:12:59+00:00Added an answer on June 3, 2026 at 9:12 am

    No, you can only do what you want if the number of arguments you’re passing is known at compile time. If you just want to convert a single string, use the -UTF8String message:

    // Example with two strings
    NSString *str1 = ...;
    NSString *str2 = ...;
    someCFunction([str1 UTF8String], [str2 UTF8String]);  // etc.
    

    But if the number of strings will vary at runtime, you’ll need to use a different API, if one is available. For example, if there’s an API that took an array of strings, you could convert the Objective-C array into a C array:

    // This function takes a variable number of strings.  Note: in C/Objective-C
    // (but not in C++/Objective-C++), it's not legal to convert 'char **' to
    // 'char *const *', so you may sometimes need a cast to call this function
    void someCFunction(const char *const *stringArray, int numStrings)
    {
        ...
    }
    
    ...
    
    // Convert Objective-C array to C array
    NSArray *objCArray = ...;
    
    int numStrings = [objCArray count];
    char **cStrArray = malloc(numStrings * sizeof(char*));
    for (int i = 0; i < count; i++)
        cStrArray[i] = [[objCArray objectAtIndex:i] UTF8String];
    
    // Call the function; see comment above for note on cast
    someCFunction((const char *const *)cStrArray, numStrings);
    
    // Don't leak memory
    free(cStrArray);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Like the JSON converter, is there any easy way to convert an object into
is there any easy way of store XML data into core data? Currently, my
Is there any easy way to convert bash output to HTML? For example, if
Is there any easy way to convert Tuple<int, string, Guid> to Tuple<int, string> ?
Is there any package or easy way to convert an ipv6 to an integer?
Is there any dark, obscured way to convert all of the method parameters to
Is there any easy way to convert a URL that contains to two-byte characters
Is there any easy way to convert a System.Net.Mail.MailMessage object to the raw mail
Is there any easy way to automatically deploy a web service / java web
Is there any easy way to tell perl now ignore everything that is printed?

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.