int main () { /* declaration and initialization of three students */ struct student stu1 = {"Michael Mouse", 93.2, 98.7, 89.6, 95.6}; struct student stu2 = {"Sebastian the Fish", 75.3, 78.8, 72.6, 92.6}; struct student stu3 = {"Shamrock the Cat", 85.3, 87.2, 78.5, 82.8}; struct student stu4; strcpy (stu4.name, "Inky the Dog"); stu4.test1 = 98.6; stu4.test2 = 86.9; stu4.test3 = 69.8; stu4.exam = 93.1; /* print initital student records */ printf ("Initial student records\n"); printf ("name test 1 test 2 test 3 final exam"); printf(" weighted average\n"); printStudent (stu1); printStudent (stu2); printStudent (stu3); printStudent (stu4); add10Percent(&stu4); printStudent (stu4); return 0; }
void changeStudent(Student * s) { printStudent(* s); strcpy(s -> name, "Jennifer Jones"); s -> year = 4; s -> GPA = 3.3; printStudent(* s); }
int main(){ int x; student *array; array = (student *)calloc(2, sizeof(student)); array[0].add = (address *)calloc(1, sizeof(address)); array[0] = readInfo(); printf("\nStudent 0:\n"); printStudent(array[0]); // for x = 0; x < 1; x++) // { // if(array[x].name != NULL){ // // free(stu1.name); // // stu1.name = (char *)NULL; // memset(array[x].name, 0, sizeof(array[x].name); // } // if(array[x].add.street != NULL){ // memset(array[x].add.street, 0, sizeof(array[x].add.street)); // } // } // if(array != NULL){ // memset(array, 0, sizeof(array); // } return 0; }
int cli_find_id(StudentList* sl) { Student* s = studentFindById(sl, cli_get_student_id()); if (s == 0L) printf("NO SUCH STUDENT\n"); else printStudent(s); return 0; }
void printStudentList (StudentList* sl) { StudentList* node; for(node = sl->next; node->next!=0L; node = node->next){ printf("------\n"); printStudent(node->student); } printf("------\n"); }
int main(int argc, char * argv[]) { Student s1; strcpy(s1.name, "Amy Smith"); s1.year = 3; s1.GPA = 3.6; changeStudent(& s1); printf("===main===\n"); printStudent(s1); return EXIT_SUCCESS; }
/* findStudent routine to find a student (by last name) in: none out: none */ void findStudent() { // declarations int i = 0; // loop counter char *findLastName; // last name to search char *lastName; // holds "current" student last name in loop int found[MAX_STUDENTS]; // array to store indices of found students int numFound = 0; // # of students found // print header printf("FIND STUDENT BY LAST NAME\n\n"); // loop until user quits do { numFound = 0; // reset # found to 0 // input last name and convert to lowercase findLastName = downcase(inputString("Enter partial or entire last name: ", 32)); printf("\n\nSearching ... "); // loop through all student records for (i = 0; i < numStudents; i++) { // set lastName to lowercase of "current" student last name lastName = downcase(students[i].lastName); // if the student last name *contains* the text the user entered if (strstr(lastName, findLastName) != NULL) { found[numFound] = i; // add student to found students array numFound ++; // increment counter } } // if we didn't find any if (numFound == 0) printf("No matches found.\n"); else // we did find at least one { // print # students found printf("Found %d students:\n\n", numFound); // loop through found students & print each for (i = 0; i < numFound; i++) { printStudent(&students[found[i]]); printf("\n"); } } // ask user for another search } while (confirm("Find another (y/n) ? ")); }
void prompt(void) { student students[STUDENT_MAX]; int i; unsigned short count = 0; while (count < STUDENT_MAX && registerStudent(&students[count])) { count++; } sortStudents(students, count); for (i = 0; i < count; i++) { printStudent(students[i]); } }
int main(){ //Allocate 100*sizeof(Student) bytes of data for storage Student students[100]; ////Fill that allocated memory and store the total number of students into count. int count = getArrayOfStudents("data", students); printf("Original record:\n\n"); printStudent(students[0]); //Change the contents of that data and call print method char *newName="Hu Li"; printf("\nRenaming to \"%s\"\n\n",newName); students[0] = renameStudent(students[0], newName); printStudent(students[0]); //Do the same thing again. newName="Balakrishnan Radhakrishnan"; printf("\nRenaming to \"%s\"\n\n",newName); students[0] = renameStudent(students[0], newName); printStudent(students[0]); }
int main() { Student pupil[MaxStudents]; char aName[MaxNameBuffer]; void getString(FILE *, char[]); int getData(FILE *, Student[]); int search(char[], Student[], int); void sort(Student[], int); void printStudent(Student); void getString(FILE *, char[]); FILE * in = fopen("input.txt", "r"); if (in == NULL) { printf("Error opening file: %s.\n", strerror(errno)); exit(1); } int numStudents = getData(in, pupil); if (numStudents == 0) { printf("No data supplied for students"); exit(1); } printf("\n"); for (int h = 0; h < numStudents; h++) printStudent(pupil[h]); printf("\n"); getString(in, aName); while (strcmp(aName, "END") != 0) { int ans = search(aName, pupil, numStudents); if (ans == -1) printf("%s not found\n", aName); else printf("%s found at location %d\n", aName, ans); getString(in, aName); } sort(pupil, numStudents); printf("\n"); for (int h = 0; h < numStudents; h++) printStudent(pupil[h]); } //end main
StudentList* queryStudentList(StudentList* sl, Student* s) { StudentList* node = sl->next; while (node->next != NULL) { if(matchesStudent(node->student ,s)) { printf("------\n"); printStudent(node->student); } node = node->next; } printf("------\n"); return 0L; }
/* listStudents print a list of all students in global students[] array in: none out: none */ void listStudents() { // declarations struct STUDENT *s; // pointer to "current" student int i; // loop counter // print headers printf("LIST ALL STUDENTS\n\n"); printf( " # Student Name\t\t\tEnrolled Credits\n" "=== ============\t\t\t========== =======\n"); // loop through all students for (i = 0; i < numStudents; i++) { s = &students[i]; // set pointer to "current" student // print the student's data printf("%3d " // ### "%-34.34s " // last, first "%10s " // mm/dd/yyyy "%7d\n", // ### i+1, formatName(s->firstName, s->lastName, 1), formatDate(s->enrollmentDate), s->completedCredits); } printf("\n"); // ask user whether to view/edit the details i = inputInteger("Type # to view/edit, or blank to return to menu. "); // if not, return if (i < 1 || i > numStudents) return; // print the student's details // (if we had more fields, they would be displayed now) printf("\n"); printStudent(&students[i-1]); printf("\n"); // edit student if user wishes to do so if (confirm("Edit this student (y/n) ? ")) editStudent(&students[i-1]); }
/*主函数*/ int StudentManagerSystemMain() { setbuf(stdout, NULL); /*取消,默认输出流存在buffer机制*/ /*函数声明*/ char menu(); /*菜单*/ struct student *create(); /*创建链表*/ struct student *insert(); /*插入节点*/ struct student *delet(); /*删除节点*/ void printStudent(); /*输出链表*/ STUDENT *find(); /*数据定义*/ struct student *head; /**/ char name[20]; int n; head = NULL; /*作空链表*/ char type=0; while ((type=menu())!='q') { switch (type) { case '0': return EXIT_SUCCESS; case '1': head = create(head); /*调用函数创建以head为头的链表*/ break; case '2': printf("\nInput the inserted num and name:\n"); gets(name); /*输入学号*/ n = atoi(name); /**/ gets(name); /*输入姓名*/ head = insert(head, name, n); /*将结点插入链表*/ break; case '3': printf("\nInput the deleted name:\n"); gets(name); /*输入被删除姓名*/ head = delet(head, name); /*调用函数删除结点*/ break; case '4': printStudent(head); /*调用函数输出节点*/ printf("press any key back..."); scanf("%c", &type); scanf("%c", &type); break; case '5': printf("\nInput the find name:\n"); gets(name); STUDENT *stu=find(head,name); break; } } // head=create(head); /*调用函数创建以head为头的链表*/ // print(head); /*调用函数输出节点*/ // // printf("\nInput the inserted num and name:\n"); // gets(name); /*输入学号*/ // n=atoi(name); /**/ // gets(name); /*输入姓名*/ // head=insert(head,name,n); /*将结点插入链表*/ // print(head); // // printf("\nInput the deleted name:\n"); // gets(name); /*输入被删除姓名*/ // head=delet(head,name); /*调用函数删除结点*/ // print(head); return EXIT_SUCCESS; }
/* == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == */ int main(int argc, char *argv[]) { CDLL list; int i,direction,k; CDLL_NODE *currNode; if (argc < 4) { printf("You must supply 3 values on the cmd line after %s:\n", argv[0]); printf("1: name of an input file contaning n names/labels of the members of the circle\n"); printf("2: an integer: m < n , indicating that every m'th member gets deleted until all the members are deleted\n"); printf("3: a string \"CW\" or \"CCW\" for clockwise counter-clockwise. This is the direction\n"); printf(" you will move as you advance around the ring deleting members\n"); exit( EXIT_FAILURE ); } k = atoi(argv[2]); /* assume valid int < n */ if (strcmp(argv[3],"CW")==0) direction = CLOCKWISE; /* follow the NEXT ptr */ else direction = COUNTERCLOCKWISE; /* follow the PREV ptr */ /* Initialize CDLL (set head ptr NULL and set the cmp function */ initList(&list, compareStudent,printStudent,freeStudent); loadList(&list,argv[1]); printf("\nLIST: ");printList(list, CLOCKWISE, BRIEF ); /* we follow the NEXT ptr around the ring, not the PREV ptr */ do /* prompt user for a member to start the counting with */ { char *andrewID; STUDENT *s = malloc(sizeof(STUDENT)); if (!s) fatal("malloc( sizeof(STUDENT)) failed in main"); currNode=NULL; printf("\nchoose an ID as the starting point in the circle: "); fflush(stdout); if (!mygetline(&andrewID,stdin)) fatal("mygetline failed on stdin."); s->andrewID = andrewID; currNode = searchList( list, s); /* Can't call freeStudent() because it will free the name and major string but we didnt put any in this one - this student only has the id field initilaized. so manually just free the andereID string then node*/ free( s->andrewID ); free( s ); } while (!currNode); while (list.head) /* WHILE THERE ARE ANY MEMBERS STILL ALIVE */ { printf("\nDELETING: "); printStudent( currNode->data, BRIEF); fflush(stdout); currNode = deleteNode( &list, currNode, direction ); if (!currNode) { printf(" <-- was the last man standing!\n"); break; } printf("\nLIST: ");printList(list, CLOCKWISE, BRIEF ); printf("RESUMING AT: "); printStudent( currNode->data, BRIEF ); printf(" and skipping %d elements \n", k ); for ( i=1 ; i<=k ; ++i ) if (direction==CLOCKWISE) currNode = currNode->next; else currNode=currNode->prev; } /* END WHILE - END OF GAME */ return EXIT_SUCCESS; }