Reputation: 67
How do I do this? This is what I've tried so far and it keeps erroring saying naughty things at me :/
char DaysOfWeek[] = { 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday' };
Upvotes: 0
Views: 8832
Reputation: 2069
There are two problems:
Like this:
char DaysOfWeek[][20] = {"Monday", "Tuesday", "Wednesday", "Thursday", "Friday" };
Upvotes: 1
Reputation: 2817
try
char * DaysOfWeek[] = { "Monday", "Tuesday", "Wednesday", "Thursday", "Friday" };
Upvotes: 4
Reputation: 4409
Your first problem is that you're defining an Array of Characters, which is just a single string. You'd want a 2D array of characters, ie. char**
, char*[]
, or char[][]
to hold multiple strings/words. Also, you need to use double quotes " "
rather than single quotes ' '
when holding Strings in C.
The next step from here depends on your errors, I would say. I also don't think you can initialize a 2D array inline like that. You'd have to do something like char[][] days = { {'M', 'o', 'n', 'd', 'a', 'y'}, ... }
I believe.
Upvotes: 1