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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T23:07:23+00:00 2026-05-30T23:07:23+00:00

This program should take 5 NSString’s in input and print them. I put them

  • 0

This program should take 5 NSString’s in input and print them.
I put them in an NSMutableArray.
During the loop if I try to print the NSString’s they’re printed correctly.
But when I try getting the objects from the array, I don’t know why it returns null.
So if I try printing them in the second loop, they’re all null.

#import <Foundation/Foundation.h>

int main (int argc, const char * argv[])
{
    NSAutoreleasePool* pool=[[NSAutoreleasePool alloc]init];
    NSMutableArray* array;
    NSString* str=[[NSString alloc]init];
    char* cstr;
    cstr=(char*)calloc(100,sizeof(char));
    for(int i=0;i<5;i++)
    {
        fgets(cstr,100,stdin);
        str=[NSString stringWithUTF8String:cstr];
        [array addObject : str];
    }
    for(int i=0;i<5;i++)
    {
        str=[array objectAtIndex:i];
        NSLog(@"%@",str);
    }        
    [pool drain];
    return 0;
}
  • 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-30T23:07:24+00:00Added an answer on May 30, 2026 at 11:07 pm

    In this line:

    NSMutableArray* array;
    

    You are declaring array, to be an NSMutableArray, but you’re not setting the pointer to anything, so array is just nil.

    You want to do this instead to allocate and initialize an actual instance of NSMutableArray and assign it to that pointer:

    NSMutableArray* array = [[NSMutableArray alloc] init];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this program that should execute a piece of code base on the
I am working on a bug in this program where it should be able
Consider this problem: I have a program which should fetch (let's say) 100 records
Edited Question: This should be clear. using System; namespace UpdateDateTimeFields { class Program {
How can I do this in a C# program? I'm pretty sure it should
Dear all,Now i have this question in my java program,I think it should be
In this program I'm parsing input into integers and I can't seem to be
Take a guess ... how long will this program take to produce the very
So, this program is supposed to take stats from Auburn's football season and compute
This should be pretty simple but for some reason, I can't get this program

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.