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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T20:19:31+00:00 2026-05-25T20:19:31+00:00

I am having troubles passing/receiving NSString pointers through function calls. I’m hoping someone can

  • 0

I am having troubles passing/receiving NSString pointers through function calls. I’m hoping someone can help me see what I’m doing incorrectly.

So this is from my first class…

void addTo(int pk, NSString* nam, NSString *descrip)
{    
    //open the database
    sqlite3 *db;
    db = [Item openDB:databasePath];

    printf("'%i', '%s', '%s'", pk, nam, descrip);
    //create new item with key, name, description, and database
    Item *Obj = [[Item alloc]initWithPrimaryKey:pk:nam:descrip:db];
                          .
                          .
                          .
}

And then this is the function in Item.m called as above…

- (id) initWithPrimaryKey:(NSInteger) pk :(NSString*) nam: (NSString*) descrip: (sqlite3*) db{

    printf("'%i', '%s', '%s'", pk, nam, descrip);
                         .
                         .
                         .
    return self;
}

Let’s say I call addTo with inputs 1234, “Tree”, “plant with leaves”

The print in the first code block outputs what I sent to addTo but the print in initWithPrimaryKey prints the following…

'1234', 'P?a', 'P?a' 

Why is this? Or more.. why is it not printing what I expect?

  • 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-25T20:19:32+00:00Added an answer on May 25, 2026 at 8:19 pm

    %s is used for char* strings, but %@ should be used with NSStrings. printf may or may not support %@, I don’t know. If not, you need to use NSString’s cStringUsingEncoding or UTF8String to convert to a char* that you can use.

    initWithPrimaryKey:pk:nam:descrip:db is invalid (or at least very loopy) syntax, BTW, as is initWithPrimaryKey:(NSInteger) pk :(NSString*) nam: (NSString*) descrip: (sqlite3*) db.

    It’s important to understand the difference between an NSString and a char* string. The NSString is a full-fledged object, with about 50 methods that it supports to do all sorts of neat/strange/(and occasionally)obscene things with string values. The two are not in any way interchangeable. And unlike with some C++ libraries, you can’t substitute a char* string for an NSString on a call and have automatic conversion occur.

    So using "letters" for a string will not produce something usable as an NSString — you must use @"letters".

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

Sidebar

Related Questions

I am having troubles with passing an object to a function using setTimeout; function
I'm having troubles when calling a function taking a pointer to a string as
I'm having trouble passing a structure array as a parameter of a function struct
I am having trouble passing data retrieved from a $.post() function to use in
I'm having trouble passing a big array to a function in C. I declare:
Ok, so I'm using Jquery's AJAX function and it's having trouble passing a URL
hey, I'm currently using the iPhone SDK and I'm having trouble passing an NSString
I am having trouble passing the url of $.PhotoUpdater.doUpdate(url) to do the doUpdate function.
I'm having trouble passing an array of structs to a function in C. I've
I am having some troubles passing a reference to an object which is of

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.