Hey all.

I've been given an exercise to code for my MCSE, which I've done, but the problem is, I don't quite understand why it works. I was given the following skeleton code, in which I have to add several functions to:

Code:
#include <iostream.h>
#include <string.h>

struct student_record {
	char name[16];
	char course[24];
	char age[3];
};

struct student_record stu_list[] = {
	"Johnson Steve", "Computer Science", "24",
	"Richards Susan", "Systems Analysis", "28",
	"Peterson Martin", "Systems Analysis", "32",
	"Smith Phyllis", "Advanced C", "43",
	"Edward Peter", "Systems Analysis", "57",
	"Bullock James", "COBOL Programming", "23",
	"Haynes Evelyn", "C Programming", "42",
	"Perro Lenardo", "Visual Basic Programmer", "22",
	"Ontand Rikard", "Software Technology", "34",
	"Iwano Morishiro", "Pascal Programming", "24",
	"\0", "\0", "\0",
};

void sort_records(struct student_record records[], int nrecords);
To this code, I have to add the main() function (obviously hehe), and produce the sort_records() function. Here's what I've added so far:

Code:
int main(void)
{
	int i;
	const int NUMRECS = (sizeof(stu_list) / sizeof(stu_list[0]));

	sort_records(stu_list, NUMRECS);

	for (i = 0; i < (NUMRECS - 1); i++)
	{
		cout << "Name: " << stu_list[i].name << endl;
		cout << "Course: " << stu_list[i].course << endl;
		cout << "Age: " << stu_list[i].age << endl;
	}

	return 0;
}

void sort_records(struct student_record records[], int nrecords)
{
	int i, j;
	struct student_record temp;

	for (i = 0; i < nrecords; i++)
	{
		for (j = i + 1; j < nrecords; j++)
		{
			if (strcmp(records[i].name, records[j].name) > 0)
			{
				temp = *(records + i);
				*(records + i) = *(records + j);
				*(records + j) = temp;
			}
		}
	}
}
After testing this, and printing the array contents (the debug loop in the main() function), it prints the contents in alphabetical order. However, I've read that you cannot copy one structure to another, or compare them etc., so I don't understand why my swapping with temp works. I can't even debug as I keep getting errors when trying to debug with this:

Code:
cout << *(records + i) << endl;
I've tried this as well:

Code:
cout << (*(records + i)) << endl;
The error I get is:

error C2679: binary '<<' : no operator defined which takes a right-hand operand of type 'struct student_record' (or there is no acceptable conversion)

So what's going on inside that nested loop? What's the pointer notation doing?

If someone could explain this to me, I'd be *very* grateful.

Thanks in advance,

John.