2330 : Introduction to Programming in C

July 9th - Next Station - Structs

Make-up class for July 4th
We have a plan regarding making up the class time we missed on the July 4th holiday. We'll tell you our situations and what we cannot do, and what we plan to do.
Midterms
We are giving you back your midterms today. I must say (just from the perspective of myself [Bigi]) that you all did pretty well -- considering the difficulty of the test. I personally think it was just right -- not too hard or too easy. That was pretty surprising, because, to tell you the truth, it was the first time I had to write exam problems, so I was kind of worrying that I would make it too easy or too hard. What do you think?
Oh, and of course we will go over the midterm today. You may want to take notes because the final exam is comprehensive, and thus may contain stuff from here.

Data Records/Structs
Your textbook calls these data records. (Refer to chapter 16 of the book) As the names sound, they are used for storing data record/an entire structure of data, with different data types. You may store as many variables as you want inside a struct. The way to declare a struct is below:
typedef struct {
  int a;
  char b;
  string c;
  // and so on. any number and any types of variables can go here.
} structname;
structname is where you put your structure's name in. You can name it anything you want. Whatever you name it, will become the name of the new data type (the structure) that you created. Then you can declare variables in your main() function (or any other functions as well) with this data type. For example if your structname was "student," then you could do this in main:
student johnny;
This would create a variable called johnny, and inside johnny is whatever variables you have put in your struct. In the above example, it would be a (an int), b (a char), and c (a string). You can access them with johnny.a, johnny.b and johnny.c, and just use them like any other variables.
You can create however many variables you want with this struct - treat it like a template. So you can do:
student may;
student eddie;
student zappa, ino;
Each of them have their own sets of "a," "b," and "c."