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
Jesse Morris
1,970 PointsIOS - Stage 3 Pointers and Memory - code: Array Length
Print the length of the array real_numbers using the sizeof() function. Your output should look like the following: Array real_numbers can store x items.
my input is this:
float real_numbers[5]; printf("Array real_numbers is %ld bytes.\n", sizeof(real_numbers)); printf("Array real_numbers can store %ld times\n", sizeof(real_numbers)/ sizeof(float));
the line I am having trouble with is:
printf("Array real_numbers can store %ld times\n", sizeof(real_numbers)/ sizeof(float));
the error code displays:
That was not the correct string. Do you have the correct format character? sizeof(real_numbers) returns a long. That format character is '%ld'.
I would appreciate if someone could tell be what I am missing in this code, I would of thought that you would have to divide the total number of bytes in the array by the number of bytes in a float as that was what was shown on the video tutorial.
2 Answers
Stone Preston
42,016 Pointsprintf("Array real_numbers can store %ld times\n", sizeof(real_numbers)/ sizeof(float));
you have times, not items. it should be
printf("Array real_numbers can store %ld items\n", sizeof(real_numbers)/ sizeof(float));
Jesse Morris
1,970 Pointsthanks, I can't believe I didn't see that! haha
Stone Preston
42,016 Pointsno worries