Bummer! You must be logged in to access this page.

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

Code challenge arrays, task 2/4

What is wrong with my code?

char letters[2]; letters[0] = 'alpha';

8 Answers

this 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);

It 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?

Hi, 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.

Hi, you can do it in one single line with

char letters[2] = {alpha};

maybe it's more clear to understand, hope this helps!

char letters[2] = {alpha};

That is correct but it doesn't work in the code challenge.

can you post the rest of the code? maybe there's other errors, in my case it worked

This 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;

I wasnt including the prior code which threw it off

char alpha = 'a'; char bravo = 'b';

char letters[2] = {alpha};