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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T12:57:07+00:00 2026-06-05T12:57:07+00:00

I’m new in Objective-C programmation and I receive this error when I run my

  • 0

I’m new in Objective-C programmation and I receive this error when I run my little program (I just want to generate a random char). So here’s what I’ve done so far:

(IBAction)generate{
  int a = arc4random() % 26;
  NSString * chaine = @"ABCDEFGHIJKLMNOPQRSTUVWXYZ";
  char lettre = [chaine characterAtIndex:a];

  NSMutableString * mot = [[NSMutableString alloc] initWithCharacters:lettre length:1];
  hasard.text = mot;
}

I tried to simply put my variable ‘lettre’ in hasard.text but it won’t work with the error ‘Incompatible integer to pointer conversion assigning to ‘NSString *‘ from ‘char‘. So I created an NSMutableString to contain my character.

When I put the character “e” manually instead of the variable ‘letter’ on the fifth line it works well. Since I can see in the debugger that ‘lettre’ contains a random letter, why do I get the error in the title ?

(EXC_BAD_ACCESS (code=2, address=0x42)).

  • 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-05T12:57:08+00:00Added an answer on June 5, 2026 at 12:57 pm

    The function is expecting a pointer to a character, you are giving it a literal character. You need to create a pointer to it. Also, characterAtIndex doesn’t return a character as you would think. It returns a unicode character which is actually an unsigned short instead of an unsigned char. However, if you change your code to this it will work:

    const unichar foo = [@"Test" characterAtIndex:0];
    NSString *test = [NSString stringWithCharacters:&foo length:1]; //Note the &
    

    EDIT But the simplest way would just be this:

    char randChar = arc4random_uniform(26) + 'A'; //Changed in response to Jason Coco's comment
    NSString *mot = [NSString stringWithFormat:@"%c", randChar];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I want use html5's new tag to play a wav file (currently only supported
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
For some reason, after submitting a string like this Jack’s Spindle from a text
this is what i have right now Drawing an RSS feed into the php,
I would like to run a str_replace or preg_replace which looks for certain words

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.