Hi to everyone,
first I would like to excuse me for asking newbie questions.
I'm studying the excellent "Beginning C for Ardunino" (Auth: Jack Purdum), and I found something I can't understand in the examples of the chapter 12, where he shows an example-library for calculating the Easter dates.
In particular...
Header file "Dates.h"
class Dates
{
public:
#define ASCIIZERO 48 // character for 0 in ASCII
struct easter {
int month;
int day;
int year;
int leap;
char easterStr[11];
};
struct easter myEaster;
// Function prototypes:
int IsLeapYear(int year);
void GetEaster(Dates *myEaster);
};
Then, he says: "The GetEaster() function is passed a pointer to an easter structure."
But, in the "Dates.cpp" file, the code for the function is:
void Dates::GetEaster(Dates *myData){ // This is line 44
int offset;
int leap;
int day;
int temp1, temp2, total;
myData->myEaster.easterStr[0] = '0'; // Always a '0'
myData->myEaster.easterStr[2] = '/'; // Always a '/'
myData->myEaster.easterStr[3] = '0'; // Assume day is less than 10
myData->myEaster.easterStr[10] = '\0'; // null char for End of string
offset = myData->myEaster.year % 19;
leap = myData->myEaster.year % 4;
...and so on
So, my questions are:
1- why in the header file, the function prototype has "Dates *myEaster" as argument, but then the book says that I have to pass a pointer to an easter structure?
2- the name in the argument of the function prototype (*myEaster) is the same of the variable (struct easter type) defined few lines before: is this mandatory or I could write the function prototype like this (for example)?
void GetEaster(Dates *myPtr);
3- this argument, points to what? To a Dates class or to the struct easter variable?
4- in the function code, the line
myData->myEaster.easterStr[0] = '0';
works only if *myData is a pointer to the Dates Class or to the struct easter variable?
5- in the ".ino" code, the function GetEaster() is called as:
myDates.GetEaster(&myDates);
And I'm passing the address of the Dates class, not the myEaster object. So, i'm looping back to the first question...
Sorry if I wrote unclear or stupid questions. But I hope you can help me to understand better.