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

  • Home
  • SEARCH
  • 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 8493607
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T23:03:55+00:00 2026-06-10T23:03:55+00:00

this is my first question in stackoverflow! im trying to reverse a string using

  • 0

this is my first question in stackoverflow!
im trying to reverse a string using two arrays in xcode, ive set up the interface,i got a button,a text field and a label.
whatever goes into the text field is reversed when the button is touched!
i got the code and it seems correct to me on paper,the problem is that when i test the application with for example “HELLO”, the content of myArray is “H E” and reverseArray is” O L L”.
id be grateful if anyone cud help im pretty fed up with tracing this code :(((
here is the code:

@interface ViewController ()
@end


@implementation ViewController
@synthesize textField,string1,string2,reverseArray,myArray;
@synthesize Label1;
- (IBAction)Reverse:(UIButton *)sender {
reverseArray=[[NSMutableArray alloc]init];
string1=[[NSString alloc]init];
string2=[[NSString alloc]init];
string1=textField.text;
myArray=[[NSMutableArray alloc]init];
    for (int i=0; i<=string1.length-1; i++) {
    [myArray insertObject:[[NSString alloc] initWithFormat:@"%c",[string1 characterAtIndex:i]] atIndex:i];

}
    for (int j=0; j<=myArray.count-1; j++) {
    [reverseArray insertObject:[myArray objectAtIndex:myArray.count-1] atIndex:j];
    [myArray removeLastObject];


}
NSLog(@"%@",myArray);
NSLog(@"%@",reverseArray);
  • 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-10T23:03:56+00:00Added an answer on June 10, 2026 at 11:03 pm

    For the second loop, you’re using myArray.count as the end condition for the “for” loop, but myArray.count is decreasing by one each iteration of the loop because you’re removing the last object from myArray each iteration. Think about it:

    First iteration:  j=0; myArray.count - 1 = 4
    Second iteration: j=1; myArray.count - 1 = 3
    Third iteration:  j=2; myArray.count - 1 = 2
    

    It stops here at the forth iteration because j=3 > myArray.count -1 = 1

    Try something like this for the second loop (Note: I’m not in front of xCode right now, so there might be errors in the following block. Take it with a grain of salt):

    for( int j = string1.length -1; j >= 0; j-- ) {
        [reverseArray addObject:[myArray objectAtIndex:j]];
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm quite new to stackoverflow and this is my first question. I am trying
this is my first question in stackoverflow. I am trying to use PHPExcel to
This is my first question on stackoverflow so I'll try to keep it concise
This is my first question on stackoverflow. I just wonder why my getJSON code
this is my first time asking a question on stackoverflow. I'm working on a
First of all, sorry if this isn't an appropriate question for StackOverflow. I've tried
This is my first post on stackoverflow, so please excuse me if my question
This is my first here in Stackoverflow. So I just want to ask question
This is my first question on StackOverflow and I've already visited every single question
first question to StackOverflow, please be gentle. I am trying to find the equation

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.