user-0 提问: 提问

回复:
user: user-1
content: 引用 4 楼 rng_nb 的回复:一楼什么鬼，发错了吧。代码应该没问题吧，按你发我的那几张要求图做的。

user: user-0
content: 一楼什么鬼，发错了吧。

user: user-2
content: 如果编写批处理文件（Windows）或者sh文件（Linux），可以利用程序的返回值（退出值）来判断程序的执行结果，以便批处理的流程处理。

user: user-3
content: 是有区别的，exit(0), exit(1);都是退出当前进程；参数0, 1表示退出的状态，0一般是正常退出，其他都是非正常退出；可以通过退出的状态判别进程是因为什么退出的。

user: user-1
content: #include <stdio.h> #include <stdlib.h> #include <string.h> #include <assert.h>  #define NAMELEN 10 #define COURSES 4  typedef struct stu_info{ 	char stu_name[NAMELEN]; 	int id, score[COURSES]; 	float avgScoure; 	struct stu_info *next; }STU_INFO;  static STU_INFO DefaultList[5] = { 	{ 		"Alice", 		1, 		{90, 80, 88, 70}, 		82.0f, 		NULL 	}, 	{ 		"Bob", 		2, 		{88, 30, 78, 77}, 		68.3f, 		NULL 	}, 	{ 		"Carol", 		3, 		{90, 95, 90, 100}, 		93.8f, 		NULL 	}, 	{ 		"Geek", 		4, 		{100, 98, 100, 100}, 		99.5f, 		NULL 	}, 	{ 		"Dave", 		5, 		{59, 59, 59, 59}, 		59.0f, 		NULL 	} };  #define MainMenu() do{\ 					printf("*******************Main Menu********************\n");\ 					printf("			1.Show Current List\n");\ 					printf("			2.Insert Student\n");\ 					printf("			3.Delete Student\n");\ 					printf("			4.Search Student\n");\ 					printf("			5.Alanyze Course\n");\ 					printf("			6.Exit The Program\n");\ 					printf("*************************************************\n");\ 				}while(0);  #define Flush() do{\ 					int ch;\ 					while((ch = getchar()) != '\n' && ch != EOF);\ 				}while(0);   #define Push(Next, Node) do{\ 							Next = Node;\ 						}while(0);	  #define CreateDefaultList(L) do{\ 								Push(DefaultList[3].next, &DefaultList[4]);\ 								Push(DefaultList[2].next, &DefaultList[3]);\ 								Push(DefaultList[1].next, &DefaultList[2]);\ 								Push(DefaultList[0].next, &DefaultList[1]);\ 								Push(L->next, &DefaultList[0]);\ 							}while(0);  void SortByAvg(STU_INFO *L) { 	int i, j, sorted, size = 0; 	STU_INFO *t, *curNode, *nextNode, *nextnextNode;  	for(t = L->next; t != NULL; t = t->next, size++); 	 	for(i = 0; i < size - 1; ++i){ 		sorted = 0;  		for(j = 0, curNode = L; j < size - 1 - i; ++j, curNode = curNode->next){ 			nextNode = curNode->next; 			nextnextNode = nextNode->next;  			if(nextNode->avgScoure < nextnextNode->avgScoure){ 				nextNode->next = nextnextNode->next; 				nextnextNode->next = nextNode; 				curNode->next = nextnextNode; 				 				sorted = 1; 			} 		}  		if(!sorted){ 			break; 		} 	} }  void ShowCurrentList(STU_INFO *L) { 	STU_INFO *t; 	int opt;  	do{ 		printf("Please Select The Show Mode :\n1>. Default				2>. Sorted\n"); 		scanf("%d", &opt); 	}while(system("clear"), opt != 1 && opt != 2);  	Flush(); 	if(opt == 2){ 		SortByAvg(L); 	}  	printf("************************************************LIST INFO**********************************************\n"); 	printf("ID		Name		CO1		CO2		CO3		CO4		Avg\n"); 	for(t = L->next; t != NULL; t = t->next){ 		printf("%d		%s		%d		%d		%d		%d		%.1f\n",	 				t->id, t->stu_name, t->score[0], t->score[1], t->score[2], t->score[3], t->avgScoure); 	} 	printf("*******************************************************************************************************\n"); }  void InsertStudent(STU_INFO *L) { 	STU_INFO *t, *node;  	for(t = L; t->next != NULL; t = t->next); 	node = malloc(sizeof(STU_INFO)); 	if(node == NULL){ 		return; 	}  	printf("Please Enter The Information Of The Student To Add :\n"); 	scanf("%d%d%d%d%d", &node->id, &node->score[0], &node->score[1], &node->score[2], &node->score[3]); 	node->avgScoure = ((float)(node->score[0] + node->score[1] + node->score[2] + node->score[3])) / 4; 	Flush(); 	fgets(node->stu_name, sizeof(node->stu_name), stdin); 	node->stu_name[strlen(node->stu_name) - 1] = '\0'; 	node->next = NULL; 	 	Push(t->next, node); 	system("clear"); 	ShowCurrentList(L); }  void DeleteStudent(STU_INFO *L) { 	STU_INFO *t, *node = NULL; 	int id;  	printf("Please Enter The ID Of The Student To Delete :\nID = "); 	scanf("%d", &id); 	Flush();  	for(t = L; t->next != NULL; t = t->next){ 		if(t->next->id == id){ 			node = t->next; 			t->next = node->next; 			break; 		} 	}  	if(node == NULL){ 		printf("Student ID <%d> Not Found.\n", id); 		return; 	} 	printf("Delete operation complete.\n");  	if(node->id >= 6){ 		free(node); 	}  	getchar(); 	system("clear"); 	ShowCurrentList(L); }  void SearchStuent(STU_INFO *L) { 	STU_INFO *t; 	char name[NAMELEN] = "";  	printf("Please Enter The Name Of The Student To Search :\nName = "); 	fgets(name, sizeof(name), stdin); 	name[strlen(name) - 1] = '\0';  	for(t = L->next; t != NULL; t =	t->next){ 		if(strncmp(name, t->stu_name, strlen(t->stu_name)) == 0){ 			printf("Student Info:\n"); 			printf("ID		Name		CO1		CO2		CO3		CO4		Avg\n"); 			printf("%d		%s		%d		%d		%d		%d		%.1f\n",	 					t->id, t->stu_name, t->score[0], t->score[1], t->score[2], t->score[3], t->avgScoure); 			return; 		} 	}  	printf("Student <%s> Not Found.\n"); }  void AnalyzeCourse(STU_INFO *L) { 	STU_INFO *t; 	int i, min, max, sumno = 0, passno = 0; 	float avg = 0.0f, passrate = 0.0f;  	printf("Please Enter The ID Of The Course To Analyze :\n"); 	scanf("%d", &i); 	Flush();  	for(t = L->next, min = max = t->score[i - 1]; t != NULL; t = t->next){ 		if(t->score[i - 1] > max){ 			max = t->score[i - 1]; 		} 		if(t->score[i - 1] < min){ 			min = t->score[i - 1]; 		}  		avg += t->score[i - 1]; 		sumno++;  		if(t->score[i - 1] >= 60){ 			passno++; 		} 	} 	avg /= sumno; 	passrate = (float)passno / sumno;  	printf("Course Info of CO%d :\n", i); 	printf("Max = %d\n", max); 	printf("Min = %d\n", min); 	printf("Avg = %.1f\n", avg); 	printf("PassingRate = %.1f\n", passrate); }  void ExitTheProgram(STU_INFO **L) { 	STU_INFO *t, *preNode; 	 	do{ 		for(t = (*L); t->next != NULL; t = t->next); 		 		if(t != *L){		 			for(preNode = (*L); preNode->next != t; preNode = preNode->next); 			preNode->next = t->next; 			if(t->id >= 6){ 				free(t); 			} 		} 	}while(t != *L);  	free(*L);  	printf("Thanks To Use The Program.\n"); }  int main(void) { 	STU_INFO *stuinfo = malloc(sizeof(STU_INFO)); 	assert(stuinfo != NULL);  	memset(stuinfo, 0, sizeof(STU_INFO));  	CreateDefaultList(stuinfo);  	int mainopt;  	void (*SubMenu[])(STU_INFO *) = { 		ShowCurrentList, 		InsertStudent, 		DeleteStudent, 		SearchStuent, 		AnalyzeCourse 	};  	while(1){ 		do{ 			system("clear"); 			MainMenu();  			printf("\nPlease Enter A Number Between 1 and 6 :\nYou Choose Menu no = "); 			scanf("%d", &mainopt); 			Flush(); 		}while((mainopt < 1 || mainopt > 6) && (system("clear"), printf("Sorry, Please Try Again\n"), getchar())); 		 		if(mainopt != 6){ 			system("clear"); 			SubMenu[mainopt - 1](stuinfo); 		}else{ 			ExitTheProgram(&stuinfo); 			break; 		}  		getchar(); 	}  	return 0; }