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 trialJoyce Thomas
Courses Plus Student 405 PointsChallenge Task 2 of 3
I keep getting an error on Task 2 of 3 which asks to print the size of the array. It doesn't like my "%ld" and I have no idea what I can do to get the code working. Can anyone tell me what is wrong with my code:
float real_numbers [5]; printf ("Array real_numbers is %lb bytes\n", sizeof(real_numbers));
6 Answers
Stone Preston
42,016 Pointsfloat real_numbers [5]; printf ("Array real_numbers is %lb bytes\n", sizeof(real_numbers));
you used %lb instead of %ld
Jason Anello
Courses Plus Student 94,610 PointsHi Joyce,
Try %ld
.
Joyce Thomas
Courses Plus Student 405 PointsThank you kindly for your help. One clarification is it an "l" as in "length" and a "d" as in dog? This is what I'm using on my PC but the character looks like a number one "1" when it is written.
Stone Preston
42,016 Pointsyes thats correct. l as in length and d as in dog. %d is for ints, however putting the l in front (%ld) means its for a long int which can store larger numbers (such as sizes in bytes which could be fairly long)
Joyce Thomas
Courses Plus Student 405 PointsThank you Stone and Jason for your help.
I am using the correct format. It is my PC and the homework work space that are at war.
I tried copying both of your "%ld" into the workspace and end up with an error. Completely frustrating!
Jason Anello
Courses Plus Student 94,610 PointsI'm on a pc myself and it is passing fine for me.
I copied Stone Preston 's code and change the 'b' as in boy, to a 'd' as in dog, and it passes.
Stone Preston
42,016 Pointshmm thats strange. just copied in your original answer but changed the format specifier and passed using
float real_numbers [5];
printf ("Array real_numbers is %ld bytes\n", sizeof(real_numbers));
Joyce Thomas
Courses Plus Student 405 PointsMy original code had "b" instead of a "d" and I looked at it 10 times and didn't see it.
Greatly appreciate the help Stone and Jason. I was tearing my hair out and I managed to write the code for three assignments once this was fixed. :)
Joyce Thomas
Courses Plus Student 405 PointsJoyce Thomas
Courses Plus Student 405 PointsThank you for your help Stone. I used percent, letter "l" as in letter and letter "d" as in dog. %ld. I am using a PC and I think it doesn't like my characters. I copied an pasted your code into the assignment and got the same error.