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
Evan Ratner
703 PointsCode challenge arrays, task 2/4
What is wrong with my code?
char letters[2]; letters[0] = 'alpha';
8 Answers
Andrea Malagoli
16,303 Pointsthis is the complete code that worked for me:
char alpha = 'a';
char bravo = 'b';
char letters[2] = {alpha};
letters[1] = bravo;
printf("letters %c %c", alpha, bravo);
Travis Favaron
13,038 PointsIt mentions in the question to use the variable alpha. So the correct code would not use a string for alpha but instead use the variable. Make sense?
bobkingstone
27,869 PointsHi, you have 'alpha' in speech marks indicating a string, when in fact you should be referencing the variable name alpha - minus the speech marks.
hope this helps.
Andrea Malagoli
16,303 PointsHi, you can do it in one single line with
char letters[2] = {alpha};
maybe it's more clear to understand, hope this helps!
Evan Ratner
703 Pointschar letters[2] = {alpha};
That is correct but it doesn't work in the code challenge.
Andrea Malagoli
16,303 Pointscan you post the rest of the code? maybe there's other errors, in my case it worked
bobkingstone
27,869 PointsThis code will work, when referencing a variable you do not add parentheses or ' '
char alpha;
char bravo;
alpha = 'a';
bravo = 'b';
char letters[2];
letters[0] =alpha;
Evan Ratner
703 PointsI wasnt including the prior code which threw it off
char alpha = 'a'; char bravo = 'b';
char letters[2] = {alpha};