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
Paul Dunahoo
5,390 PointsObjective-C Basics: Arrays Code Challenge
Embarrassingly, I can't figure out this question: "Declare 2 separate variables of type char named "alpha" and "bravo". Assign the letter 'a' to the variable "alpha" and the letter 'b' to "bravo"."
Here is the code I wrote:
char letters[a, b] = {"alpha", "bravo"};
I have also tried a bunch of other things. I tried a similar method used in the float example in the video that preceded this code challenge, but I think there is a difference between the two that I missed.
8 Answers
Jonathan Howell
1,581 Pointschar alpha = 'a'; char bravo = 'b';
char letters[2]; letters[0] = alpha; letters[1] = bravo;
Jonathan Howell
1,581 PointsShould look like this...
char alpha = 'a'; char bravo = 'b';
Paul Dunahoo
5,390 PointsThanks :)
Paul Dunahoo
5,390 PointsOkay, the printf code is a little easier once you figure out the formatting for it.
printf("letters %c %c", letters[0], letters[1]);
(use /n to create a new line in your own code)
Avi Bortnick
117 PointsWhen I had the line break \n in my code, I was getting an error, but it was fine in Xcode. Anyway, thanks for posting the help.
Jonathan Howell
1,581 PointsNo problem, let me know if you figure out the "Print the results" section!
Paul Dunahoo
5,390 PointsOkay, I can't figure out section 2 now :P I keep re-watching the video, but I have no clue what I am missing. All this code works just fine in Xcode.
Here is my section 2 or 4 code challenge code:
char letters[1] = {"alpha", "bravo"};
Jonathan Howell
1,581 PointsLet me know if you figure out the printf code...
Paul Dunahoo
5,390 PointsI got it, thankfully.
Jonathan Howell
1,581 PointsThat's where I am lost is on the printf step.. Help! Haha
Jonathan Howell
1,581 PointsGracias!
Paul Dunahoo
5,390 PointsYou're welcome!
Paul Dunahoo
5,390 PointsPaul Dunahoo
5,390 PointsOh, I finally get it! The code is not getting replaced, it is building on top of itself. Thanks again!