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' };
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' };
try
char * DaysOfWeek[] = { "Monday", "Tuesday", "Wednesday", "Thursday", "Friday" };
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.
There are two problems:
Like this:
char DaysOfWeek[][20] = {"Monday", "Tuesday", "Wednesday", "Thursday", "Friday" };
In C, you need to use double quotes ("foo"
) to enclose strings. Single quotes ('a') are for characters.
You also need to declare your variable as an array of strings, not as a single string, as Ricky Mutschlechner pointed out.