Strings mostly!

I'm probably asking a question that occurs time and time again - so my apologies.
I have a DS3231 RTC module. I think I am using code from ladyada but I'm not certain of that, however I have programmed the RTC successfully and modified the code so the print out reads Weekday, Date, Month, Year, Hour, Minute and Second.
The weekday comes from the RTC as a number - 1 to 7 - I can convert that to the day name with 'if' statements but I believe there is a neater way using what I remember as 'string slicing'. I have tried the following from Arduino Reference but it doesn't cut the mustard.

75 char* weekday[] = {"Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday";}

Verifying the sketch with the above line commented out brings no objection but when I uncomment it I get:

RTC_1_v2.ino: In function 'void printDate()':
RTC_1_v2:75: error: expected `}' before ';' token
RTC_1_v2:75: error: scalar object 'weekday' requires one element in initializer
RTC_1_v2.ino:67: warning: unused variable 'second'
RTC_1_v2.ino:68: warning: unused variable 'minute'
RTC_1_v2.ino:69: warning: unused variable 'hour'
RTC_1_v2.ino:70: warning: unused variable 'day'
RTC_1_v2.ino:71: warning: unused variable 'date'
RTC_1_v2.ino:72: warning: unused variable 'month'
RTC_1_v2.ino:73: warning: unused variable 'year'
RTC_1_v2.ino:75: warning: unused variable 'weekday'
RTC_1_v2.ino: At global scope:
RTC_1_v2:79: error: expected constructor, destructor, or type conversion before '.' token
RTC_1_v2:80: error: expected constructor, destructor, or type conversion before '.' token
RTC_1_v2:81: error: expected constructor, destructor, or type conversion before '.' token
RTC_1_v2:82: error: expected constructor, destructor, or type conversion before '.' token
RTC_1_v2:83: error: expected constructor, destructor, or type conversion before '.' token
RTC_1_v2:84: error: expected constructor, destructor, or type conversion before '.' token
RTC_1_v2:85: error: expected constructor, destructor, or type conversion before '.' token
RTC_1_v2:86: error: expected constructor, destructor, or type conversion before '.' token
RTC_1_v2:87: error: expected constructor, destructor, or type conversion before '.' token
RTC_1_v2:88: error: expected constructor, destructor, or type conversion before '.' token
RTC_1_v2:89: error: expected constructor, destructor, or type conversion before '.' token
RTC_1_v2:90: error: expected constructor, destructor, or type conversion before '.' token
RTC_1_v2:91: error: expected constructor, destructor, or type conversion before '.' token
RTC_1_v2:92: error: expected declaration before '}' token

Can someone explain what's happening (simply please) and how I might phrase the string declaration?

"Saturday";} // your comma should be on the outside.

There could also be more mistakes elsewhere too, so please post the full code.

I apologise for 'going too early'!!! I was editing my post and clicked on the wrong choice!!!

I spent most of yesterday evening to get that line to work. After all, I'd copied it direct from Arduino Reference, so it should have worked, shouldn't it? No?

This morning I tried again, added a curly bracket and deleted a conflicting line I'd forgotten about and then I saw what the error report was hinting at. At this point I mistakenly posted my message! However, the code in Arduino Reference has a curly-wurly after the semicolon, putting it before it solved the problem.

I'm a beginner with C++ having only a long disused ability in Basic, so that makes me long in the tooth and short on brain cells associated with memory. I find it extremely difficult to understand and harder still to remember what I learn.

However, the code in Arduino Reference has a curly-wurly after the semicolon, putting it before it solved the problem.

It is just a overlooked mistake made by the person who wrote that part. Finding out that there are mistakes in the reference page, is nothing new.

Continuing with my lack of knowledge -

Why is it that a Verify procedure seems to complete successfully yet some lines of the error report are red?

I would have liked to include the sketch itself as well as the error report but what comes out after selecting 'Copy for Forum' from the Edit menu does not seem to be the sketch at all! Plainly it's not just a matter of simply pasting from the clipboard. Similary, the error report provides the option of copying to clipboard but only if it terminates with an error - or am I wrong?

I need to clear up these matters because I have a feeling I'll be banging on a bit about my misunderstandings.

Dont use the Copy for Forum option, just press CTRL+ A and copy and paste it manually.

Although I cannot see how to 'insert code' in this post as advised, her is my sketch. I cannot understand how the conversion from BCD to Decimal and vice-versa works. Why can I only get the correct day name if I subtract 1 from the 'day' variable?

//Arduino 1.0+ only

#include "Wire.h"
#define DS1307_ADDRESS 0x68
byte zero = 0x00; //workround for issue #527

void setup(){
Wire.begin();
Serial.begin(9600);

//MUST CONFIGURE IN FUNCTION. IF RTC IS NOT ALREADY INITIALLISED,
//UPLOAD by uncommenting this command. Comment out again then upload
//again otherwise the clock will be reset to initial condition each
//time the processor restarts.

//setDateTime();
}
void loop(){
printDate();
delay (1000);
}

void setDateTime(){

byte second= 1; //0-59
byte minute= 35; //0-59
byte hour= 19; //0-23
byte day= 4; //1-7, Sunday-Saturday.
byte date= 12; //1-31
byte month = 11 ; // 1-12
byte year= 14; //0-99

Wire.beginTransmission(DS1307_ADDRESS);
Wire.write(zero); //Stop oscillator.
Wire.write(decToBcd(second));
Wire.write(decToBcd(minute));
Wire.write(decToBcd(hour));
Wire.write(decToBcd(day));
Wire.write(decToBcd(date));
Wire.write(decToBcd(month));
Wire.write(decToBcd(year));

Wire.write(zero); //Start.

Wire.endTransmission();

}

byte decToBcd(byte val){ //Convert decimal to binary encoded decimal.
return ( (val/10*16)+(val%10) );
}

byte bcdToDec(byte val){ //Convert binary encoded decimal to decimal.
return ( (val/16*10)+(val%16) );
}

void printDate(){ //Reset the register pointer.

Wire.beginTransmission(DS1307_ADDRESS);
Wire.write(zero); //Stop Oscillator.
Wire.endTransmission();

Wire.requestFrom(DS1307_ADDRESS,7);

int second = bcdToDec(Wire.read());
int minute = bcdToDec(Wire.read());
int hour = bcdToDec(Wire.read()& 0b111111); //24 hour time.
int day = bcdToDec(Wire.read()); //0-6 Sunday to Saturday.
int date = bcdToDec(Wire.read());
int month = bcdToDec(Wire.read());
int year = bcdToDec(Wire.read());

char* weekday[] = {"Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"};

// Now print date.
Serial.print(weekday[day-1]);
Serial.print(" ");
//Serial.print(day);
//Serial.print(" ");
Serial.print(date);
Serial.print("/");
Serial.print(month);
Serial.print("/");
Serial.print(year);
Serial.print(" ");
Serial.print(hour);
Serial.print(".");
Serial.print(minute);
Serial.print(".");
Serial.println(second); //Note println! Next line!
}

Although I cannot see how to 'insert code' in this post as advised, her is my sketch.

The layout is new, so you can either write the code tags ([ code ] ... [/ code]) yourself or click the blue <> button above the smiley faces.

I cannot understand how the conversion from BCD to Decimal and vice-versa works

Why can I only get the correct day name if I subtract 1 from the 'day' variable?

That is because an array starts at index 0. So to see "Sunday" you do weekday[0], weekday[1] = "Monday" and so on.

Thanks for all of that.

One last thing for now - I was looking for an explanation of these two functions from the sketch:

 byte decToBcd(byte val){                      //Convert decimal to binary encoded decimal.
  return ( (val/10*16)+(val%10) );
 }
  
 byte bcdToDec(byte val){                      //Convert binary encoded decimal to decimal.
  return ( (val/16*10)+(val%16) );
 }

the thing to keep in mind about BCD is that each nibble (4 bits) is a digit character. With that in mind, check:

Ok say you have a value of 96 and you put it into decToBCD(96), it will look at the numbers individually (both nibbles) and convert them to the corresponding binary representation.
0 = 0000
1 = 0001
2 = 0010
. . .
9 = 1001
A = 1010
B = 1011
C = 1100
D = 1101
E = 1110
F = 1111

So 96(dec) -> 10010110(BDC)

And it is the opposite for BDCtodec, 10010110(BDC) ->96(dec)