int main(void) { struct stu_t *p = NULL; struct stu_t *p1 = NULL; int count; FILE *fp = NULL; int i, ret; p = creat_stu(&count); print_student(p, count); if (NULL == (fp = fopen("./files/3stu.txt", "w+"))) { perror("fopen"); return 1; } ret = fwrite(p, sizeof(struct stu_t), count, fp); printf("already write p into the file. ret = %d\n", ret); rewind(fp); p1 = malloc(sizeof(struct stu_t) * count); ret = fread(p1, sizeof(struct stu_t), count, fp); printf("already read from file into p1. ret = %d\n", ret); print_student(p1, count); fclose(fp); free(p); return 0; }
void print_all_student_info(void) { int i = 0; for( ; i < num_of_student; ++i ) { // note: it's invisible to know the sizeof (struct student) print_student( (void*)((char*)(student*)S + student_struct_size*i) ); } }
int sort_score() { int i,j; char buffer[MAX_NAME]; int temp; for(i = 0; i < student_count; i++){ for(j = 0; j < student_count -i; j++){ if(stu[j].score < stu[j+1].score){ strcpy(buffer, stu[j].name); strcpy(stu[j].name,stu[j+1].name); strcpy(stu[j+1].name,buffer); temp = stu[j].number; stu[j].number = stu[j+1].number; stu[j+1].number = temp; temp = stu[j].score; stu[j].score = stu[j+1].score; stu[j+1].score = temp; } } } print_student(); }
int main(void) { int choice; if(file2mem() == FAIL){ printf("信息文件读取出错\n"); return 1; } while(1){ print_choice(); scanf("%d",&choice); switch(choice){ case ADD: add_student();break; case DEL: delete_student();break; case CGE: change_student();break; case F_NAME: find_name();break; case F_NUM: find_number();break; case SORT: sort_score();break; case PRT: print_student();break; case EXIT: return 0; } getchar(); printf("请按任意继续\n"); getchar(); } }
int main(void) { struct student students[MAX_STUDENT] = {{0}}; struct student *std; while ((std = read_student()) != NULL) { add_student(students,std); } print_student(students); printf("\nClass AVG.:\t%f\n", class_average(students)); }
//打印当前学生的信息 void print_loginstudent() { CLEAR_SCREEN(); printf("\033[33m\033[2;54H%s\033[0m","您的学生信息如下:\n"); printf("\033[33m\033[4;10H%s\033[0m","学生ID\t\t学生姓名\t学生年龄\t学生班级\t语文成绩\t数学成绩\tC语言成绩\t平均成绩\n"); print_student(stulogin->dat); getchar(); getchar(); }
int main(int argc, const char *argv[]) { int aa; sample(&aa); struct student a = {1, 100, "jack"}; struct student b = a; print_student(&a); return 0; }
void print_students(student_node *head) { student_node *iterator = head; if (iterator->current != NULL) { //printf("Student number: %d name: %s\n", iterator->current->student_number, iterator->current->firstName); print_student(iterator->current); } if(iterator->next != NULL){ print_students(iterator->next); } }
int main() { student* db[2]; // Legt Datenbank mit Platz für 2 Zeiger auf Studenten an int i; db[0] = new_student("Max Mustermann"); add_exam(db[0], "GTI", 4); add_exam(db[0], "SyA", 3); db[1] = new_student("Sepp Wurz"); add_exam(db[1], "GTI", 1); add_exam(db[1], "SyA", 1); add_exam(db[1], "ThI", 2); for(i = 0; i < 2; ++i) print_student(db[i]); return 0; }
int main(void) { //declare the array of students apvector <STUDENT_TYPE> list(10); // input the list of students for(int i = 0; i < 10; i++) { cout<<"Please enter information for student " << i+1 << endl << endl; list[ i ] = get_student( ); //use function to get individual info } // print the array of students one struct at a time for(int j = 0; j < 10; j++) { print_student(list [ j ] ); } return 0; }
/* This main function does a little testing Like all good CS Majors you should test your code here. There is no substitute for testing and you should be sure to test for all edge cases e.g., calling remove_front on an empty list. */ int main(void) { /* Now to make use of all of this stuff */ list* llist = create_list(); /* What does an empty list contain? Lets use our handy traversal function */ printf("TEST CASE 1\nAn Empty list should print nothing here:\n"); traverse(llist, print_student); printf("\n"); /* Lets add a student and then print */ push_front(llist, create_student("Mahmoud", "Joudeh", 20)); printf("TEST CASE 2\nA List with one student should print that student:\n"); traverse(llist, print_student); printf("\n"); /* Lets remove that student and then print */ remove_front(llist, free_student); printf("TEST CASE 3\nAnother Empty list should print nothing here:\n"); traverse(llist, print_student); printf("\n"); /* Lets add two elements and then print */ push_front(llist, create_student("Alex", "Ikonomidis", 19)); push_front(llist, create_student("Andrew", "Kim", 21)); printf("TEST CASE 4\nA List with two students should print those two students:\n"); traverse(llist, print_student); printf("\n"); /* Lets copy this list */ list* llist2 = copy_list(llist, copy_student); printf("TEST CASE 5\nA copied list should print out the same two students:\n"); traverse(llist, print_student); printf("\n"); /* Lets kill the list */ empty_list(llist, free_student); printf("TEST CASE 6\nAfter freeing all nodes the list should be empty:\n"); traverse(llist, print_student); printf("\n"); empty_list(llist2, free_student); free(llist); free(llist2); /* YOU ARE REQUIRED TO MAKE MORE TEST CASES THAN THE ONES PROVIDED HERE */ /* You will get points off if you do not you should at least test each function here */ /*Sample Tests*/ llist = create_list(); printf("\n4 Elements added\n "); push_front(llist, create_student("Abra", "Cadabra",14)); push_front(llist, create_student("bing", "google", 10)); push_front(llist, create_student("costa", "rica", 10)); push_front(llist, create_student("Delta", " ", 17)); //push_front(llist, NULL); traverse(llist, print_student); printf("\n"); printf("Removed %d elements of age 10\n", remove_if(llist, age_is_ten, free_student)); traverse(llist, print_student); remove_front(llist, free_student); list* list2 = copy_list(llist, copy_student); remove_front(llist, free_student); remove_back(list2, free_student); printf("\nEmptying list \n"); traverse(llist, print_student_simple); i = 0; printf("\n500 elements being added\n"); while(i++ < 500) { push_front(llist, create_student("sdflj", "sdlfs", rand()%10)); } printf("\nis Empty? %d\n", is_empty(llist)); printf("\n"); //traverse(llist, print_student); i = 0; printf("\nRemoving 500 elements until empty\n"); while(!is_empty(llist)){ remove_front(llist, free_student); //practice(llist); } printf("\nis Empty? %d\n", is_empty(llist)); empty_list(llist, free_student); remove_if(llist, trueVal, free_student); traverse(llist, print_student); printf("\n"); printf("\nEmptiness\n"); remove_back(llist, free_student); traverse(llist, print_student); traverse(list2, print_student); /* Testing over clean up*/ empty_list(llist, free_student); empty_list(list2, free_student); free(llist); free(list2); printf("\nAdding random numbers to the list\n"); llist = create_list(); i = 0; while (i < sizeof(numeros)/sizeof(numeros[0])) push_back(llist, create_student("a", "ab", numeros[i++])); traverse(llist, print_student_simple); printf("\n"); printf("\nRemoving numbers in a random order\n"); i = 0; while( i < sizeof(_numeros)/sizeof(_numeros[0])) { int total = remove_if(llist, randomizer, free_student); printf("size is %d after %d removes of %d: ", size(llist), total, _numeros[i]); traverse(llist, print_student_simple); printf("\n"); i++; } printf("\nEmpty size: \n"); printf("list of size %d: ", size(llist));traverse(llist, print_student_simple); printf("\nTesting push_back and remove_if\n"); push_back(llist, create_student("a", "b", 9)); traverse(llist, print_student_simple); printf("\n"); remove_if(llist, age_is_ten, free_student); traverse(llist, print_student_simple); printf("\n"); empty_list(llist, free_student); traverse(llist, print_student_simple); printf("\n"); printf("\nTesting push_front and remove_if\n"); push_front(llist, create_student("a", "b", 9)); traverse(llist, print_student_simple); printf("\n"); remove_if(llist, age_is_ten, free_student); traverse(llist, print_student_simple); printf("\n"); empty_list(llist, free_student); traverse(llist, print_student_simple); printf("\n"); printf("\nTesting push_back and remove_if\n"); push_back(llist, create_student("a", "b", 10)); traverse(llist, print_student_simple); printf("\n"); remove_if(llist, age_is_ten, free_student); traverse(llist, print_student_simple); printf("\n"); printf("\nTesting push_front and remove_if\n"); push_front(llist, create_student("a", "b", 10)); traverse(llist, print_student_simple); printf("\n"); remove_if(llist, age_is_ten, free_student); traverse(llist, print_student_simple); printf("\n"); printf("\nTesting push_back and remove_front\n"); push_back(llist, create_student("a", "b", 9)); traverse(llist, print_student_simple); printf("\n"); remove_front(llist, free_student); traverse(llist, print_student_simple); printf("\n"); printf("\nTesting push_back and remove_back\n"); push_back(llist, create_student("a", "b", 9)); traverse(llist, print_student_simple); printf("\n"); remove_back(llist, free_student); traverse(llist, print_student_simple); printf("\n"); printf("\nTesting push_front and remove_front\n"); push_front(llist, create_student("a", "b", 9)); traverse(llist, print_student_simple); printf("\n"); remove_front(llist, free_student); traverse(llist, print_student_simple); printf("\n"); printf("\nTesting push_front and remove_back\n"); push_front(llist, create_student("a", "b", 9)); traverse(llist, print_student_simple); printf("\n"); remove_back(llist, free_student); traverse(llist, print_student_simple); printf("\n"); printf("\nEVERYTHING WORKS!!!\n"); i = 0; printf("\n Testing return value of remove_if on empty list\n"); while(i++ < 6) printf("%d ",remove_if(llist, trueVal, free_student)); printf("\n Testing return value of remove_front on empty list\n"); i = 0; while(i++ < 6) printf("%d ", remove_front(llist, free_student)); printf("\n Testing return value of remove_back on empty list\n"); i = 0; while(i++ < 6) printf("%d ", remove_back(llist, free_student)); printf("\n Testing return value of remove_if on filled list\n"); i = 0; while(i++ < 6) push_back(llist, create_student("a", "b", 3)); i = 0; while(i++ < 6) printf("%d ",remove_if(llist, trueVal, free_student)); printf("\n Testing return value of remove_front on filled list\n"); i = 0; while(i++ < 6) push_back(llist, create_student("a", "b", 3)); i = 0; while(i++ < 6) printf("%d ",remove_front(llist,free_student)); printf("\n Testing return value of remove_back on filled list\n"); i = 0; while(i++ < 6) push_back(llist, create_student("a", "b", 3)); i = 0; while(i++ < 6) printf("%d ",remove_back(llist,free_student)); printf("\nTesting size: "); i = 0; while(i++ < 6) push_back(llist, create_student("a", "b", 3)); printf("\nsize %d: ", size(llist)); printf("\nEmptying it: "); empty_list(llist, free_student); printf("\tsize %d: ", size(llist)); i = 0; while(i++ < 6) push_back(llist, create_student("a", "b", numeros[i])); printf("\nTesting copy method, values getting squared\n"); printf("\n"); list2 = copy_list(llist, copy_student0); traverse(llist, print_student_simple); printf("\n"); traverse(list2, print_student_simple); printf("\n"); printf("\nTesting front and back methods:\n"); printf("Front: ");print_student(front(llist)); printf("\nBack: ");print_student(back(llist)); printf("\n_Front: ");print_student(front(list2)); printf("\n_Back: ");print_student(back(list2)); printf("\nTesting remove_front and remove_back together\n"); i = 0; while (i++ < 6) { remove_back(llist, free_student); printf("\n"); traverse(llist, print_student_simple); remove_front(list2, free_student); printf("\n"); traverse(list2, print_student_simple); } printf("\nEmptying the list\n"); while(i++ < 9) empty_list(llist, free_student); printf("\nAdding a null element\n"); push_back(llist, NULL); traverse(llist, print_student_simple); list *list3 = create_list(); empty_list(list3, free_student_nulls); print_student_simple(front(list3)); traverse(list3, print_student_simple); empty_list(llist, free_student_nulls); empty_list(list2, free_student); push_back(llist, create_student("one", "two", 5)); push_back(list2, create_student("one", "two", 10)); printf("\nTesting front and back methods with one element\n"); printf("Front: ");print_student_simple(front(llist)); printf("\nBack: ");print_student_simple(back(llist)); printf("\n_Front: ");print_student_simple(front(list2)); printf("\n_Back: ");print_student_simple(back(list2)); empty_list(llist, free_student_nulls); empty_list(list2, free_student_nulls); printf("\nTesting front and back methods with empty list\n"); printf("Front: ");print_student_simple(front(llist)); printf("\nBack: ");print_student_simple(back(llist)); printf("\n_Front: ");print_student_simple(front(list2)); printf("\n_Back: ");print_student_simple(back(list2)); printf("\nAll Empty List : \""); traverse(llist, print_student_simple); traverse(list2, print_student_simple); printf("\"\n"); empty_list(list3, free_student); printf("\nYAY\n"); free(llist); free(list2); free(list3); //cd /mnt/hgfs/B/Current\ Projects/HW\ 11\ \(2110\)/ return 0; }