0

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' };
jmj
  • 237,923
  • 42
  • 401
  • 438
user2308700
  • 67
  • 3
  • 7
  • 5
    Well, read closely at those **naughty things** first, I'm sure they are helpful. – Yu Hao Jul 08 '14 at 04:13
  • http://stackoverflow.com/questions/1088622/how-do-i-create-an-array-of-strings-in-c – deru Jul 08 '14 at 04:26
  • Possible duplicate of [Array of all NSDate for a week](http://stackoverflow.com/questions/10957200/array-of-all-nsdate-for-a-week) – Kindle Q Feb 03 '17 at 12:06

4 Answers4

4

try

char * DaysOfWeek[] = { "Monday", "Tuesday", "Wednesday", "Thursday", "Friday" };
chouaib
  • 2,763
  • 5
  • 20
  • 35
1

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.

Ricky Mutschlechner
  • 4,291
  • 2
  • 31
  • 36
1

There are two problems:

  1. You need to use double quotes in C literal strings.
  2. This is a two dimensional array, you need to give some constant value to the second dimension.

Like this:

char DaysOfWeek[][20] = {"Monday", "Tuesday", "Wednesday", "Thursday", "Friday" };
dvai
  • 1,953
  • 3
  • 13
  • 15
0

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.

user3553031
  • 5,990
  • 1
  • 20
  • 40