学生管理系统(功能并不完善)

来源:互联网 发布:刷钻了 淘宝刷钻网 编辑:程序博客网 时间:2024/05/22 08:28

心得:
1.第一次写终端上显示操作选项的代码:
system(“clear”):清屏操作
sleep(2) : 延时2秒
return语句:原来不大懂干嘛的,只知道返回函数的返回值;原来是函数遇到return语句就会退出此函数

2.修改程序前,本程序通过“end”结束while循环,但是“end”却保留到了下一个指针里,以至于在输出学生信息是总是会在最后一行出现end 0 0 0现象,或者在冒泡排序的时候,end这一行信息会参与排序,后来通过冒泡排序的循环次数分别再减1,完美消除这一烦恼。

3.存在的问题 :只能一次输入学生信息,后来再想输入学生信息就会覆盖之前的学生信息。

以下是网上查找的信息:exit() 和 return

2 函数: exit() 编辑

函数名: exit()

所在头文件:stdlib.h

功 能: 关闭所有文件,终止正在执行的进程。

exit(1)表示异常退出.这个1是返回给操作系统的。

exit(x)(x不为0)都表示异常退出

exit(0)表示正常退出

exit()的参数会被传递给一些操作系统,包括UNIX,Linux,和MS DOS,以供其他程序使用。

stdlib.h: void exit(int status);

参 数 : status //程序退出的返回值.

exit()和return的区别:

按照ANSI C,在最初调用的main()中使用return和exit()的效果相同。

但要注意这里所说的是“最初调用”。如果main()在一个递归程序中,exit()仍然会终止程序;但return将

控制权移交给递归的前一级,直到最初的那一级,此时return才会终止程序。return和exit()的另一个区别

在于,即使在除main()之外的函数中调用exit(),它也将终止程序。

_exit()与exit的区别:

头文件:

exit:#include

#include <stdio.h>#include <stdlib.h>#include<string.h>struct student{    char name[20];    int id;    int math;    int china;};typedef struct student STU;void show(){    system("clear");    printf("************************************\n\n");    printf("*****WELCOME TO TEACHER SYSTEM******\n\n");    printf("************************************\n\n");    sleep(2);    system("clear");}
void PrintInfo(){    printf("*************************************\n\n");    printf("**1.InsertInfo         2.SearchInfo**\n");    printf("**3.SortInfo           4.ChangeInfo**\n");    printf("**5.ShowInfo           6.Quit      **\n");    printf("*************************************\n\n");    printf("Please input your choice :\n");}void InsertInfo(STU *s[]){    int i = 0;    printf("Please Input Information :\n");    while(1)    {        s[i] = (STU *)malloc(sizeof(STU));        if (NULL == s[i])        {            printf("Malloc Failure !\n");            return;        }        scanf("%s", s[i]->name);        if (strcmp(s[i]->name, "end") == 0)        {            break;        }        scanf("%d%d%d", &s[i]->id, &s[i]->math, &s[i]->china);        i++;    }}
void SearchInfo(STU *s[]){       int i = 0;    char target[10] = {0};    STU *t    printf("Please input name you will find :\n");    scanf("%s", target);    while(s[i] != NULL)    {        if(strcmp(s[i]->name, target) == 0)        {            printf("**************\n");            printf("name : %s\n", s[i]->name);                t = s[n];                s[n] = s[n + 1];                s[n + 1] = t;            printf("id   : %d\n", s[i]->id);            printf("math : %d\n", s[i]->math);            printf("china: %d\n", s[i]->china);            printf("**************\n");            return;        }        i++;    }    printf("**************\n");    printf("Not Find !\n");    printf("**************\n");}
void SortInfo(STU *s[]){    int i = 0;    int j = 0;    int len;    STU *t;    int p;    printf("Please select :math or china ?\n");    scanf("%d",&p);    switch (p)    {        case 1 :    while(s[i++] != NULL);    i--;    len = --i;    for (j = 0; j < len - 2; j++)    {        for (i = 0; i < len - j - 2; i++)            if (s[i]->math > s[i + 1]->math)            {                t = s[i];                s[i] = s[i + 1];                s[i + 1] = t;            }     }    printf("XingMing\t\txuehao\t\tshuxue\t\tyuwen\n");    for (i = 0; i < len; i++)        printf("%s\t\t%d\t\t%d\t\t%d\n",s[i]->name, s[i]->id, s[i]->math, s[i]->china);    break;
    case 2 :    while(s[i++] != NULL);    i--;    len = --i;    for (j = 0; j < len - 2; j++)    {        for (i = 0; i < len - j - 2; i++)            if (s[i]->math > s[i + 1]->math)            {                t =  s[i];                s[i] = s[i + 1];                s[i + 1] = t;            }     }    printf("XingMing\t\txuehao\t\tshuxue\t\tyuwen\n");    for (i = 0; i < len; i++)        printf("%s\t\t%d\t\t%d\t\t%d\n",s[i]->name, s[i]->id, s[i]->math, s[i]->china);    break;        default :    printf("Unkown !\n");    }}
void ChangeInfo(STU *s[]){    char target[10] = {0};    int i= 0;    printf("Please Input The Name You Want Change :\n");    scanf("%s", target);    printf("Input New Infor :\n");    while(s[i] != NULL)    {        if(strcmp(s[i]->name, target) == 0)        {            scanf("%s", s[i]->name);            scanf("%d", &s[i]->id);            scanf("%d", &s[i]->math);            scanf("%d", &s[i]->china);            printf("Change Success!\n");            return;        }        i++;    }}
void ShowInfo(STU *s[]){    int len;    int i = 0;    while(s[i++] != NULL);    i--;    len = i--;    printf("XingMing xuehao shuxue  yuwen");    for (i = 0; i < len; i++)    {        printf("%s\t%d\t%d\t%d\n",s[i]->name, s[i]->id, s[i]->math, s[i]->china);    }}
int main(){    STU *stu[100] = {0};    char choice[10] = {0};    show();    while (1)    {        PrintInfo();        scanf("%s", choice);        switch (atoi(&choice[0]))        {            case 1:                InsertInfo(stu);                break;             case 2:                SearchInfo(stu);                break;             case 3:                SortInfo(stu);                break;            case 4:                ChangeInfo(stu);                break;            case 5:                ShowInfo(stu);                 break;            case 6:                exit(0);                 break;            default:                printf("Unkown Input!\n");                break;         }    }       return 0;}
原创粉丝点击