Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

iOS Objective-C Basics (Retired) Pointers and Memory Array Size and Length

Do not understand what the error message means. It tells me I have the correct string but not the correct format.

Isn't %s the correct formatting for a string? When I do this in Xcode it compiles and gives me "Array real_numbers is 20 bytes." Why does the Treehouse console say it is wrong? And what would be correct?

float real_numbers[5];
printf("Array %s is %ld bytes.\n", "real_numbers", sizeof(real_numbers));

1 Answer

Hi Abbey,

I feel like the message that the challenge is giving you is confusing. The issue isn't that %s is the wrong formatter - that is the correct one to use with a string - it is that the string within the quotes is not formatted as TH expects it to be...that's confusing, I know, so here you go:

When you check your work TH sees this - literally:

"Array %s is %ld bytes."

When what it is expecting - literally is:

"Array real_numbers is %ld bytes."

If you replace your %s with "real_numbers" and remove "real_numbers" as the second argument you're sending to printf, your code will pass - as such:

float real_numbers[5];
printf("Array real_numbers is %ld bytes.", sizeof(real_numbers));

I'm not sure if it is a bug or just a poorly 'formatted' question and response. I hope this helps you out.

Ok well I feel a bit better because that is actually what I gave it as my answer the first time however THIS is the error message it gave me for that:

Make sure you are calling printf and passing a string (not an NSString) and "real_numbers" as the parameters. The correct format option is '%ld'.

Which as you can imagine confused me no end and so I continued to try various combos.

But now I realize for whatever reason when I did it the first time I wrote &ld not %ld. Perhaps my brain is done for the evening. :)