testing structure
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 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 | #include <stdio.h> #include <stdlib.h> #define NUMBER_OF_CLASS 2 struct Student { char name[20]; int korean; int english; int math; }; void input (struct Student* _Class[], int Number_Of_Class); void _input (struct Student* __Class); void __input (struct Student ___Class); void Display_Class (struct Student* _Class[], int Number_Of_Class, int Number_Of_Student); int main(void) { struct Student* _Class[NUMBER_OF_CLASS] = { 0, }; int Maximum_Number_Of_Student = 50; // Dynamic memory allocation int index = 0; for (index = 0; index < NUMBER_OF_CLASS; index++) { _Class[index] = (struct Student*) calloc (Maximum_Number_Of_Student, sizeof (struct Student)); if ((struct Student*)_Class[index] == (char) 0) { printf ("Error! Dynamic memory allocation, main()\n"); return -1; } } //print Display_Class (_Class, NUMBER_OF_CLASS, Maximum_Number_Of_Student); input ((struct Student**) _Class, NUMBER_OF_CLASS); // class, student //_input ((struct Student*)* _Class); // student //__input(** _Class); // value //print Display_Class (_Class, NUMBER_OF_CLASS, Maximum_Number_Of_Student); // free () for (index = 0; index < NUMBER_OF_CLASS; index++) { if ((struct Student*) _Class[index] != (char) 0) _Class[index] = (char) 0; free ((struct Student*) _Class[index]); } return 0; } void Display_Class (struct Student* _Class[], int Number_Of_Class, int Number_Of_Student) { int _class = 0, student = 0; for (_class = 0; _class < NUMBER_OF_CLASS; _class++) { for (student = 0; student < Number_Of_Student; student++) { printf ("<< [%2d] Class >> [%2d]", _class + 1, student + 1); printf ("%s %d %d %d\n",(*(*(_Class + _class) + student)).name, (*(*(_Class + _class) + student)).korean, (*(*(_Class + _class) + student)).english, (*(*(_Class + _class) + student)).math); } printf ("\n"); } } void input (struct Student* _Class[], int Number_Of_Class) { // Call by adress or call by reference, call by value int Number_Of_Student = 3; int _class = 0, student = 0; for (_class = 0; _class < NUMBER_OF_CLASS; _class++) { for (student = 0; student < Number_Of_Student; student++) { printf (">> [%2d] Class << [%2d]", _class + 1, student + 1); (char*) gets ((char*) (*(*(_Class + _class) + student)).name); } printf("\n"); } printf ("=============\n\n"); return; } void _input (struct Student* __Class) { // call by adress or call by reference, call by value int Number_Of_Student = 3; int student = 0; for (student = 0; student < Number_Of_Student; student++) { printf (">> [%2d] Class << [%2d]", 1, student + 1); (char*) gets ((char*) (*(__Class + student)).name); } printf("\n"); return; } void __input (struct Student ___Class) { // call by value int Number_Of_Student = 1; printf (">> [%2d] Class << [%2d]", 1, 1); (char*) gets ((char*) ___Class.name); printf("\n"); return; } | cs |
0 개의 댓글:
댓글 쓰기