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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T01:11:56+00:00 2026-06-05T01:11:56+00:00

I have the following code to read a credit card number from a text

  • 0

I have the following code to read a credit card number from a text field and store it in a datamodel. The card number is correct when it is stored but later when I try to read from it it has become gibberish. Now I am guessing this is because the memory is reclaimed and it no longer makes sense.

Code to set the card number from the label:

        [cardInfo setCardNumber: [textField.text cStringUsingEncoding:[NSString defaultCStringEncoding]]];

Code in the data model:

    - (void) setCardNumber:(char *)number{
            cardNumber = number;
            //Value of cardNumber here is correct
    }

Everything looks correct until I use the property to retrieve the value at a later time.

  • 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-05T01:11:57+00:00Added an answer on June 5, 2026 at 1:11 am

    From the docs for -[NSString cStringUsingEncoding:]:

    The returned C string is guaranteed to be valid only until either the
    receiver is freed, or until the current autorelease pool is emptied,
    whichever occurs first. You should copy the C string or use
    getCString:maxLength:encoding: if it needs to store the C string
    beyond this time.

    Also, you should never use +[NSString defaultCStringEncoding]. It’s completely unreliable and can’t generally represent arbitrary strings. From the docs:

    in general this encoding should be used rarely, if at all

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

Sidebar

Related Questions

I have the following basic code to read a text file from a StreamReader:
I have following code - methods to read XML files. But it works very
I have the following code to read messages sent from a server to the
So I have the following code where I should read a Text File (This
I have the following code in my view, but it's pretty hard to read.
I have the following code to read in from a file #include <queue> #include
I have the following code that uses Sequence objects to read data from a
I have the following piece of code to read Japanese Kanji characters from UTF-8
I have the following code to read data from my .plist for use in
I have the following code to read a text file. const string FILENAME =

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.