ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
C programming session 09
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.
23.
24.
25.
26.
27.
28.
29.
30.
31.
Editor's Notes
Begin the session by explaining the objectives of the session.
Discuss the need for structures. Compare structure with an array.
Use this slide to test the student’s understanding on defining structures.
Discuss the advantages of using a label in defining a structure. Tell the students that a structure variable can be directly assigned to another structure variable of the same type. You need not to copy elements individually.
Use this slide to test the student’s understanding on defining structures.
Tell the students that structures can be passed to other functions. The structures can be passed either by value or by reference.
Use this slide to test the student’s understanding on passing structures to functions.
Use this slide to test the student’s understanding on array of structures.
Tell the students the way to access the elements of a structure, which is contained in another structure. Also, discuss the use of the typedef statement.
Use this slide to test the student’s understanding on typedef statement.
Use this slide to test the student’s understanding on the fwrite() function.
Tell the students that they can use the feof() function to check for the end of file. The feof () function does not report end-of-file unless we try to read past the last character of the file. Consider the following code. while (!feof (fp)) { fread (&buf, sizeof (struct buf) , 1 , fp) ; printf (…) ; /* print data from structure */ } Once the last record is read , the feof () function does not return a non-zero value. It senses the end-of-file only after the next read which fails. The buffer buf would still contain the contents of the last record which will be printed again. An alternative would be: while (1) { fread (&buf , sizeof (struct buf) , 1 , fp) ; if (! feof ()) printf (…) ; /* print data from structure */ }
Use this slide to test the student’s understanding on the fwrite() and fread() function.
Use this slide to test the student’s understanding on reading and writing structures in a file.
Use this and the next slide to summarize the session.