kjwyzz
2021-05-26 00:07
采纳率: 71.4%
浏览 79

有无大佬看看,新手,代码运行很有问题,球球了

#include <stdio.h>
#include <string.h>
#include<stdlib.h>
struct Student
{
    int num;
    char name[20];
    int  age;
    char sex;
    struct birth
    {
        int year;
        int month;
        int day;
    } birthday;
    char address[50];
    char tel[12];
    char Email[20];
} stu,stu1;
void insert(struct Student *stu,int N)
{
    int i;
    printf("请根据提示按照格式录入信息!\n");
    printf("学生学号\t学生姓名\t年龄\t性别\t出生年份\t出生月份\t出生日\t地址\t电话号码\t邮箱\n");
    for(i=0; i<N; i++)
        scanf("%d%s%d%s%d%d%d%s%s%s",&stu[i].num,stu[i].name,&stu[i].age,&stu[i].sex,&stu[i].birthday.year,&stu[i].birthday.month,&stu[i].birthday.day,stu[i].address,stu[i].tel,stu[i].Email);
    /*FILE *fp;
    fp=fopen("ccccc.txt","wt+");
    fwrite(stu,sizeof(struct Student),N,fp);
    fflush(stdin);
    fclose(fp);*/
    system("pause");
}
void disp(struct Student *stu,int N)
{
    /*FILE *fp;
    fp=fopen("ccccc.txt","wt+");
    fread(stu1,sizeof(struct Student),N,fp);*/
    int i;
    for(i=0; i<N; i++)
        printf("%d %s %d %s %d %d %d %s %s %s\n",stu[i].num,stu[i].name,stu[i].age,stu[i].sex,stu[i].birthday.year,stu[i].birthday.month,stu[i].birthday.day,stu[i].address,stu[i].tel,stu[i].Email);
    //fclose(fp);
    system("pause");
}

void find(struct Student *stu,int N)
{
    int i,n,xh,flag=0;
    char name[20];
    printf("请输入想要查询的方式:1  2");
    scanf("%d",&n);

    if(n==1)
    {
        printf("请输入要查找的学号:");
        scanf("%d",&xh);

        for(i=0; i<N; i++)
            if(xh==stu[i].num)
            {
                flag = 1;
                printf("学生学号\t学生姓名\t年龄\t性别\t出生年份\t出生月份\t出生日\t地址\t电话号码\t邮箱\n");
                printf("--------------------------------------------------------------------\n");
                printf("%d %s %d %s %d %d %d %s %s %s\n",stu[i].num,stu[i].name,stu[i].age,stu[i].sex,stu[i].birthday.year,stu[i].birthday.month,stu[i].birthday.day,stu[i].address,stu[i].tel,stu[i].Email);
            }
        if (0 == flag)
            printf("该学号不存在!\n");
    }



    else if(n==2)
    {
        printf("请输入要查找的姓名:");
        scanf("%s",name);
        for(i=0; i<N; i++)
            while(strcmp(name,stu[i].name)==0)
            {
                flag = 1;
                printf("学生学号\t学生姓名\t年龄\t性别\t出生年份\t出生月份\t出生日\t地址\t电话号码\t邮箱\n");
                printf("--------------------------------------------------------------------\n");
                printf("%d %s %d %s %d %d %d %s %s %s\n",stu[i].num,stu[i].name,stu[i].age,stu[i].sex,stu[i].birthday.year,stu[i].birthday.month,stu[i].birthday.day,stu[i].address,stu[i].tel,stu[i].Email);
            }
        if (0 == flag)
            printf("该姓名不存在!\n");

    }

    else
        printf("NULL!");
    system("pause");


}


void modify( struct Student *stu,int N)
{
    int i, choice, num=-1,xh,flag=0;
    int year,month,day;
    char sex, name[20],tel[20], add[20],mail[20];
    printf("请输入要要修改的学生的学号:\n");
    scanf("%d", &xh);
    for (i=0;i<N;i++)
    {
        num=i;
        if (stu[i].num==xh)
        {
            printf("------------------\n");
            printf("1.修改姓名\n");
            printf("2.修改年龄\n");
            printf("3.修改性别\n");
            printf("4.修改出生年份\n");
            printf("5.修改出生月份\n");
            printf("6.修改出生日\n");
            printf("7.修改地址\n");
            printf("8.修改电话号码\n");
            printf("9.修改邮箱\n");
            printf("10.修改完成!\n");
            while (flag==0)
            {
                printf("请选择:");
                scanf("%d", &choice);
                switch (choice)
                {
                case 1:
                    printf("请输入新的姓名:\n");
                    scanf("%s", name);
                    strcpy(stu[num].name, name);
                    break;
                case 2:
                    printf("请输入新的年龄:\n");
                    scanf("%d", stu[num].age);
                    break;
                case 3:
                    printf("请输入新的性别:\n");
                    scanf("%s", &sex);
                    stu[i].sex = sex;
                    break;
                case 4:
                    printf("请输入新的出生年份:\n");
                    scanf("%d", &year);
                    stu[num].birthday.year = year;
                    break;
                case 5:
                    printf("请输入新的出生月份:\n");
                    scanf("%d", &month);
                    stu[num].birthday.month = month;
                    break;
                case 6:
                    printf("请输入新的出生日:\n");
                    scanf("%d", &day);
                    stu[num].birthday.day = day;
                    break;
                case 7:
                    printf("请输入新的地址:\n");
                    scanf("%s", &add);
                    strcpy(stu[num].address, add);
                    break;
                case 8:
                    printf("请输入新的电话号码:\n");
                    scanf("%s", &tel);
                    strcpy(stu[num].tel, tel);
                    break;
                case 9:
                    printf("请输入新的邮箱:\n");
                    scanf("%s", &mail);
                    strcpy(stu[num].Email, mail);
                    break;
                case 10:
                    flag=1;
                default:
                    printf("请在1-9之间选择\n");
                }
            }
            printf("修改完毕!请及时保存!\n");
        }
        else
        {
            printf("没有该学生学号!!!");
        }
    }
    system("pause");
}
void delete(struct Student *stu,int *N)
{
    //FILE *fp1;
    //fp1=fopen("bbbbb.txt","wt+");
    int i, j,xh,flag = 0;
    char s1[20];
    printf("请输入要删除学生的学号:\n");
    scanf("%d", &xh);
    for (i = 0; i <*N; i++)
    {
        if (stu[i].num==xh)
        {

            flag = 1;
            for (j = i; j <(*N)-1; j++)
            {
                stu[j] = stu[j + 1];
            }
        }
    }
    if (flag==0)
    {
        printf("该学号不存在!\n");
    }
    if (flag==1)
    {
        printf("成功将该学生信息删除,并保留在别的文件中!\n");

        (*N)--;
    }
    system("pause");
}
  void add(struct Student *stu,int *N) 
{
	int i,m,j,flag,k;
	k=(*N);
	printf("请输入待增加的学生数:\n");
	scanf("%d", &m);
    stu=(struct Student *)malloc(sizeof(struct Student)*((*N)+m));

	if (m>0){
		do
		{
			flag = 1;
			while (flag)
			{
				flag = 0;
				printf("请输入第%d位学生的学号:\n", k + 1);
				scanf("%d",&stu[k].num);
				for (j = 0; j < k; j++){
					if (stu[k].num==stu[j].num)
                        {
						printf("该学号已存在\n");
						flag = 1;
						break;
					}
				}
			}
			printf("学生学号\t学生姓名\t年龄\t性别\t出生年份\t出生月份\t出生日\t地址\t电话号码\t邮箱\n");
    for(i=0; i<m; i++)
        scanf("%d%s%d%s%d%d%d%s%s%s",&stu[(*N)+i].num,stu[(*N)+i].name,&stu[(*N)+i].age,&stu[(*N)+i].sex,&stu[(*N)+i].birthday.year,&stu[(*N)+i].birthday.month,&stu[(*N)+i].birthday.day,stu[(*N)+i].address,stu[(*N)+i].tel,stu[(*N)+i].Email);

			if (0 == flag)
            {
				k++;
			}
		} while (k<(*N)+m);
	}
		(*N)=(*N)+m;
		system("pause");
}


int main()
{
    int num,flag=1,N;
    printf("请输入要录入的学生信息个数\n");
    scanf("%d",&N);
    struct Student *stu;
    stu=(struct Student *)malloc(sizeof(struct Student)*N);
    struct Student *stu1;
    stu1=(struct Student *)malloc(sizeof(struct Student)*N);
    while (flag!=0)
    {
        printf("  *************************************************\n\n");
        printf("  *                学生信息管理系统              *\n \n");
        printf("  *************************************************\n\n");
        printf("********************系统功能菜单*********************\n");
        printf("     ----------------------   ---------------------- \n");
        printf("     *********************************************   \n");
        printf("        1.录入学生信息         2.浏览当前信息        \n");
        printf("     *********************************************   \n");
        printf("     *  3.查询学生信息         4.修改学生信息        \n");
        printf("     *********************************************   \n");
        printf("     *  5.删除学生信息         6 增添学生信息        \n");
        printf("     ********************** **********************   \n");
        printf("     ----------------------   ---------------------- \n");
        printf("请选择菜单编号:");
        scanf("%d", &num);
        switch (num)
        {
        case 1:
            insert(stu,N);
            break;
        case 2:
            disp(stu,N);
            break;
        case 3:
            find(stu,N);
            break;
        case 4:
            modify(stu, N);
            break;
        case 5:
            delete(stu, &N);
            break;
        case 6:
            add(stu,&N);
            break;
        case 7:
            flag=0;
            printf("即将退出程序!\n");
        default:
            printf("NULL\n");
        }
    }
    return 0;
}
  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

4条回答 默认 最新

  • 胖哥王老师 2021-05-26 08:23
    已采纳

    楼上的专家,并不是出现编译问题,而是运行问题,在录入学生的函数中

    26行

    scanf("%d%s%d%s%d%d%d%s%s%s",&stu[i].num,stu[i].name,&stu[i].age,&stu[i].sex,&stu[i].birthday.year,&stu[i].birthday.month,&stu[i].birthday.day,stu[i].address,stu[i].tel,stu[i].Email);

    这句话是有问题的,需要空格加以区分,(此处有些数据输入,是有格式限制的,例如性别,最好加以提示,后期需要优化)

    scanf("%d %s %d %s %d %d %d %s %s %s",&stu[i].num,stu[i].name,&stu[i].age,&stu[i].sex,&stu[i].birthday.year,&stu[i].birthday.month,&stu[i].birthday.day,stu[i].address,stu[i].tel,stu[i].Email);

    输入就没有问题了,然后查询的话,会报段错误,因为其中性别,是一个字符,所以不能用%s,只能用%c

    14行,修改为,第四个参数为%c接收。

    printf("%d %s %d %c %d %d %d %s %s %s\n",stu[i].num,stu[i].name,stu[i].age,stu[i].sex,stu[i].birthday.year,stu[i].birthday.month,stu[i].birthday.day,stu[i].address,stu[i].tel,stu[i].Email);
    

    类似的还有几处,包括还有一些输入字符串的时候,不需要取地址的错误,所有这些在编译的时候会出现报警,一定要注意,一些警告,也是错误,以下是修改过明显错误的代码,详细没有再调试,可以再看看还有没有其他问题

    #include <stdio.h>
    #include <stdbool.h>
    #include <stdlib.h>
    #include <string.h>
    
    
    
    struct Student
    {
        int num;
        char name[20];
        int  age;
        char sex;
        struct birth
        {
            int year;
            int month;
            int day;
        } birthday;
        char address[50];
        char tel[12];
        char Email[20];
    } stu,stu1;
    void insert(struct Student *stu,int N)
    {
        int i;
        printf("请根据提示按照格式录入信息!\n");
        printf("学生学号\t学生姓名\t年龄\t性别\t出生年份\t出生月份\t出生日\t地址\t电话号码\t邮箱\n");
        for(i=0; i<N; i++)
            scanf("%d %s %d %c %d %d %d %s %s %s",&stu[i].num,stu[i].name,&stu[i].age,&stu[i].sex,&stu[i].birthday.year,&stu[i].birthday.month,&stu[i].birthday.day,stu[i].address,stu[i].tel,stu[i].Email);
    
    	/*{
    		FILE *fp;
    		fp=fopen("ccccc.txt","wt+");
    		fwrite(stu,sizeof(struct Student),N,fp);
    		fflush(stdin);
    		fclose(fp);
    
    	}*/
        //system("pause");
    }
    void disp(struct Student *stu,int N)
    {
        /*FILE *fp;
        fp=fopen("ccccc.txt","wt+");
        fread(stu1,sizeof(struct Student),N,fp);*/
        int i;
        for(i=0; i<N; i++)
            printf("%d %s %d %c %d %d %d %s %s %s\n",stu[i].num,stu[i].name,stu[i].age,stu[i].sex,stu[i].birthday.year,stu[i].birthday.month,stu[i].birthday.day,stu[i].address,stu[i].tel,stu[i].Email);
        //fclose(fp);
        system("pause");
    }
    void find(struct Student *stu,int N)
    {
        int i,n,xh,flag=0;
        char name[20];
        printf("请输入想要查询的方式:1  2");
        scanf("%d",&n);
        if(n==1)
        {
            printf("请输入要查找的学号:");
            scanf("%d",&xh);
            for(i=0; i<N; i++)
                if(xh==stu[i].num)
                {
                    flag = 1;
                    printf("学生学号\t学生姓名\t年龄\t性别\t出生年份\t出生月份\t出生日\t地址\t电话号码\t邮箱\n");
                    printf("--------------------------------------------------------------------\n");
                    printf("%d %s %d %c %d %d %d %s %s %s\n",stu[i].num,stu[i].name,stu[i].age,stu[i].sex,stu[i].birthday.year,stu[i].birthday.month,stu[i].birthday.day,stu[i].address,stu[i].tel,stu[i].Email);
                }
            if (0 == flag)
                printf("该学号不存在!\n");
        }
     
        else if(n==2)
        {
            printf("请输入要查找的姓名:");
            scanf("%s",name);
            for(i=0; i<N; i++)
                while(strcmp(name,stu[i].name)==0)
                {
                    flag = 1;
                    printf("学生学号\t学生姓名\t年龄\t性别\t出生年份\t出生月份\t出生日\t地址\t电话号码\t邮箱\n");
                    printf("--------------------------------------------------------------------\n");
                    printf("%d %s %d %c %d %d %d %s %s %s\n",stu[i].num,stu[i].name,stu[i].age,stu[i].sex,stu[i].birthday.year,stu[i].birthday.month,stu[i].birthday.day,stu[i].address,stu[i].tel,stu[i].Email);
                }
            if (0 == flag)
                printf("该姓名不存在!\n");
        }
        else
            printf("NULL!");
        system("pause");
     
    }
     
    void modify( struct Student *stu,int N)
    {
        int i, choice, num=-1,xh,flag=0;
        int year,month,day;
        char sex, name[20],tel[20], add[20],mail[20];
        printf("请输入要要修改的学生的学号:\n");
        scanf("%d", &xh);
        for (i=0;i<N;i++)
        {
            num=i;
            if (stu[i].num==xh)
            {
                printf("------------------\n");
                printf("1.修改姓名\n");
                printf("2.修改年龄\n");
                printf("3.修改性别\n");
                printf("4.修改出生年份\n");
                printf("5.修改出生月份\n");
                printf("6.修改出生日\n");
                printf("7.修改地址\n");
                printf("8.修改电话号码\n");
                printf("9.修改邮箱\n");
                printf("10.修改完成!\n");
                while (flag==0)
                {
                    printf("请选择:");
                    scanf("%d", &choice);
                    switch (choice)
                    {
                    case 1:
                        printf("请输入新的姓名:\n");
                        scanf("%s", name);
                        strcpy(stu[num].name, name);
                        break;
                    case 2:
                        printf("请输入新的年龄:\n");
                        scanf("%d",&stu[num].age);
                        break;
                    case 3:
                        printf("请输入新的性别:\n");
                        scanf("%c", &sex);
                        stu[i].sex = sex;
                        break;
                    case 4:
                        printf("请输入新的出生年份:\n");
                        scanf("%d", &year);
                        stu[num].birthday.year = year;
                        break;
                    case 5:
                        printf("请输入新的出生月份:\n");
                        scanf("%d", &month);
                        stu[num].birthday.month = month;
                        break;
                    case 6:
                        printf("请输入新的出生日:\n");
                        scanf("%d", &day);
                        stu[num].birthday.day = day;
                        break;
                    case 7:
                        printf("请输入新的地址:\n");
                        scanf("%s", add);
                        strcpy(stu[num].address, add);
                        break;
                    case 8:
                        printf("请输入新的电话号码:\n");
                        scanf("%s", tel);
                        strcpy(stu[num].tel, tel);
                        break;
                    case 9:
                        printf("请输入新的邮箱:\n");
                        scanf("%s", mail);
                        strcpy(stu[num].Email, mail);
                        break;
                    case 10:
                        flag=1;
                    default:
                        printf("请在1-9之间选择\n");
                    }
                }
                printf("修改完毕!请及时保存!\n");
            }
            else
            {
                printf("没有该学生学号!!!");
            }
        }
        system("pause");
    }
    void delete(struct Student *stu,int *N)
    {
        //FILE *fp1;
        //fp1=fopen("bbbbb.txt","wt+");
        int i, j,xh,flag = 0;
        //char s1[20];
        printf("请输入要删除学生的学号:\n");
        scanf("%d", &xh);
        for (i = 0; i <*N; i++)
        {
            if (stu[i].num==xh)
            {
                flag = 1;
                for (j = i; j <(*N)-1; j++)
                {
                    stu[j] = stu[j + 1];
                }
            }
        }
        if (flag==0)
        {
            printf("该学号不存在!\n");
        }
        if (flag==1)
        {
            printf("成功将该学生信息删除,并保留在别的文件中!\n");
            (*N)--;
        }
        system("pause");
    }
      void add(struct Student *stu,int *N) 
    {
    	int i,m,j,flag,k;
    	k=(*N);
    	printf("请输入待增加的学生数:\n");
    	scanf("%d", &m);
        stu=(struct Student *)malloc(sizeof(struct Student)*((*N)+m));
    	if (m>0){
    		do
    		{
    			flag = 1;
    			while (flag)
    			{
    				flag = 0;
    				printf("请输入第%d位学生的学号:\n", k + 1);
    				scanf("%d",&stu[k].num);
    				for (j = 0; j < k; j++){
    					if (stu[k].num==stu[j].num)
                            {
    						printf("该学号已存在\n");
    						flag = 1;
    						break;
    					}
    				}
    			}
    			printf("学生学号\t学生姓名\t年龄\t性别\t出生年份\t出生月份\t出生日\t地址\t电话号码\t邮箱\n");
        for(i=0; i<m; i++)
            scanf("%d %s %d %c %d %d %d %s %s %s",&stu[(*N)+i].num,stu[(*N)+i].name,&stu[(*N)+i].age,&stu[(*N)+i].sex,&stu[(*N)+i].birthday.year,&stu[(*N)+i].birthday.month,&stu[(*N)+i].birthday.day,stu[(*N)+i].address,stu[(*N)+i].tel,stu[(*N)+i].Email);
    			if (0 == flag)
                {
    				k++;
    			}
    		} while (k<(*N)+m);
    	}
    		(*N)=(*N)+m;
    		system("pause");
    }
     
    int main()
    {
        int num,flag=1,N;
        printf("请输入要录入的学生信息个数\n");
        scanf("%d",&N);
        struct Student *stu;
        stu=(struct Student *)malloc(sizeof(struct Student)*N);
        //struct Student *stu1;
        //stu1=(struct Student *)malloc(sizeof(struct Student)*N);
        while (flag!=0)
        {
            printf("  *************************************************\n\n");
            printf("  *                学生信息管理系统              *\n \n");
            printf("  *************************************************\n\n");
            printf("********************系统功能菜单*********************\n");
            printf("     ----------------------   ---------------------- \n");
            printf("     *********************************************   \n");
            printf("        1.录入学生信息         2.浏览当前信息        \n");
            printf("     *********************************************   \n");
            printf("     *  3.查询学生信息         4.修改学生信息        \n");
            printf("     *********************************************   \n");
            printf("     *  5.删除学生信息         6 增添学生信息        \n");
            printf("     ********************** **********************   \n");
            printf("     ----------------------   ---------------------- \n");
            printf("请选择菜单编号:");
            scanf("%d", &num);
            switch (num)
            {
            case 1:
                insert(stu,N);
                break;
            case 2:
                disp(stu,N);
                break;
            case 3:
                find(stu,N);
                break;
            case 4:
                modify(stu, N);
                break;
            case 5:
                delete(stu, &N);
                break;
            case 6:
                add(stu,&N);
                break;
            case 7:
                flag=0;
                printf("即将退出程序!\n");
            default:
                printf("NULL\n");
            }
        }
        return 0;
    }
    
    
    点赞 打赏 评论
  • CSDN专家-微编程 2021-05-26 00:17

    这位同学,你犯了一个低级的错误,就是方法命名不规范导致的程序运行不出来,在你的删除方法中delete在c++里面是一个函数,在dev-c++里面或者其他软件编译程序的时候会报错:[Error] expected unqualified-id before 'delete',正确的方法就是吧177行的delete改成其他的名字例如del,如果对你有帮助记得点击采纳哈~

     

    点赞 2 打赏 评论
  • 答题大神 2021-05-26 08:24
    #include <stdio.h>
    #include <string.h>
    #include<stdlib.h>
    struct Student
    {
        int num;
        char name[20];
        int  age;
        char sex;
        struct birth
        {
            int year;
            int month;
            int day;
        } birthday;
        char address[50];
        char tel[12];
        char Email[20];
    } stu,stu1;
    void insert(struct Student *stu,int N)
    {
        int i;
        printf("请根据提示按照格式录入信息!\n");
        printf("学生学号\t学生姓名\t年龄\t性别\t出生年份\t出生月份\t出生日\t地址\t电话号码\t邮箱\n");
        for(i=0; i<N; i++)
            scanf("%d%s%d%s%d%d%d%s%s%s",&stu[i].num,&stu[i].name,&stu[i].age,&stu[i].sex,&stu[i].birthday.year,&stu[i].birthday.month,&stu[i].birthday.day,&stu[i].address,&stu[i].tel,&stu[i].Email);
        /*FILE *fp;
        fp=fopen("ccccc.txt","wt+");
        fwrite(stu,sizeof(struct Student),N,fp);
        fflush(stdin);
        fclose(fp);*/
        system("pause");
    }
    void disp(struct Student *stu,int N)
    {
        /*FILE *fp;
        fp=fopen("ccccc.txt","wt+");
        fread(stu1,sizeof(struct Student),N,fp);*/
        int i;
        for(i=0; i<N; i++)
            printf("%d %s %d %s %d %d %d %s %s %s\n",stu[i].num,stu[i].name,stu[i].age,stu[i].sex,stu[i].birthday.year,stu[i].birthday.month,stu[i].birthday.day,stu[i].address,stu[i].tel,stu[i].Email);
        //fclose(fp);
        system("pause");
    }
    void find(struct Student *stu,int N)
    {
        int i,n,xh,flag=0;
        char name[20];
        printf("请输入想要查询的方式:1  2");
        scanf("%d",&n);
        if(n==1)
        {
            printf("请输入要查找的学号:");
            scanf("%d",&xh);
            for(i=0; i<N; i++)
                if(xh==stu[i].num)
                {
                    flag = 1;
                    printf("学生学号\t学生姓名\t年龄\t性别\t出生年份\t出生月份\t出生日\t地址\t电话号码\t邮箱\n");
                    printf("--------------------------------------------------------------------\n");
                    printf("%d %s %d %s %d %d %d %s %s %s\n",stu[i].num,stu[i].name,stu[i].age,stu[i].sex,stu[i].birthday.year,stu[i].birthday.month,stu[i].birthday.day,stu[i].address,stu[i].tel,stu[i].Email);
                }
            if (0 == flag)
                printf("该学号不存在!\n");
        }
     
        else if(n==2)
        {
            printf("请输入要查找的姓名:");
            scanf("%s",name);
            for(i=0; i<N; i++)
                while(strcmp(name,stu[i].name)==0)
                {
                    flag = 1;
                    printf("学生学号\t学生姓名\t年龄\t性别\t出生年份\t出生月份\t出生日\t地址\t电话号码\t邮箱\n");
                    printf("--------------------------------------------------------------------\n");
                    printf("%d %s %d %s %d %d %d %s %s %s\n",stu[i].num,stu[i].name,stu[i].age,stu[i].sex,stu[i].birthday.year,stu[i].birthday.month,stu[i].birthday.day,stu[i].address,stu[i].tel,stu[i].Email);
                }
            if (0 == flag)
                printf("该姓名不存在!\n");
        }
        else
            printf("NULL!");
        system("pause");
     
    }
     
    void modify( struct Student *stu,int N)
    {
        int i, choice, num=-1,xh,flag=0;
        int year,month,day;
        char sex, name[20],tel[20], add[20],mail[20];
        printf("请输入要要修改的学生的学号:\n");
        scanf("%d", &xh);
        for (i=0;i<N;i++)
        {
            num=i;
            if (stu[i].num==xh)
            {
                printf("------------------\n");
                printf("1.修改姓名\n");
                printf("2.修改年龄\n");
                printf("3.修改性别\n");
                printf("4.修改出生年份\n");
                printf("5.修改出生月份\n");
                printf("6.修改出生日\n");
                printf("7.修改地址\n");
                printf("8.修改电话号码\n");
                printf("9.修改邮箱\n");
                printf("10.修改完成!\n");
                while (flag==0)
                {
                    printf("请选择:");
                    scanf("%d", &choice);
                    switch (choice)
                    {
                    case 1:
                        printf("请输入新的姓名:\n");
                        scanf("%s", name);
                        strcpy(stu[num].name, name);
                        break;
                    case 2:
                        printf("请输入新的年龄:\n");
                        scanf("%d", stu[num].age);
                        break;
                    case 3:
                        printf("请输入新的性别:\n");
                        scanf("%s", &sex);
                        stu[i].sex = sex;
                        break;
                    case 4:
                        printf("请输入新的出生年份:\n");
                        scanf("%d", &year);
                        stu[num].birthday.year = year;
                        break;
                    case 5:
                        printf("请输入新的出生月份:\n");
                        scanf("%d", &month);
                        stu[num].birthday.month = month;
                        break;
                    case 6:
                        printf("请输入新的出生日:\n");
                        scanf("%d", &day);
                        stu[num].birthday.day = day;
                        break;
                    case 7:
                        printf("请输入新的地址:\n");
                        scanf("%s", &add);
                        strcpy(stu[num].address, add);
                        break;
                    case 8:
                        printf("请输入新的电话号码:\n");
                        scanf("%s", &tel);
                        strcpy(stu[num].tel, tel);
                        break;
                    case 9:
                        printf("请输入新的邮箱:\n");
                        scanf("%s", &mail);
                        strcpy(stu[num].Email, mail);
                        break;
                    case 10:
                        flag=1;
                    default:
                        printf("请在1-9之间选择\n");
                    }
                }
                printf("修改完毕!请及时保存!\n");
            }
            else
            {
                printf("没有该学生学号!!!");
            }
        }
        system("pause");
    }
    void del(struct Student *stu,int *N)
    {
        //FILE *fp1;
        //fp1=fopen("bbbbb.txt","wt+");
        int i, j,xh,flag = 0;
        char s1[20];
        printf("请输入要删除学生的学号:\n");
        scanf("%d", &xh);
        for (i = 0; i <*N; i++)
        {
            if (stu[i].num==xh)
            {
                flag = 1;
                for (j = i; j <(*N)-1; j++)
                {
                    stu[j] = stu[j + 1];
                }
            }
        }
        if (flag==0)
        {
            printf("该学号不存在!\n");
        }
        if (flag==1)
        {
            printf("成功将该学生信息删除,并保留在别的文件中!\n");
            (*N)--;
        }
        system("pause");
    }
      void add(struct Student *stu,int *N) 
    {
    	int i,m,j,flag,k;
    	k=(*N);
    	printf("请输入待增加的学生数:\n");
    	scanf("%d", &m);
        stu=(struct Student *)malloc(sizeof(struct Student)*((*N)+m));
    	if (m>0){
    		do
    		{
    			flag = 1;
    			while (flag)
    			{
    				flag = 0;
    				printf("请输入第%d位学生的学号:\n", k + 1);
    				scanf("%d",&stu[k].num);
    				for (j = 0; j < k; j++){
    					if (stu[k].num==stu[j].num)
                            {
    						printf("该学号已存在\n");
    						flag = 1;
    						break;
    					}
    				}
    			}
    			printf("学生学号\t学生姓名\t年龄\t性别\t出生年份\t出生月份\t出生日\t地址\t电话号码\t邮箱\n");
        for(i=0; i<m; i++)
            scanf("%d%s%d%s%d%d%d%s%s%s",&stu[(*N)+i].num,stu[(*N)+i].name,&stu[(*N)+i].age,&stu[(*N)+i].sex,&stu[(*N)+i].birthday.year,&stu[(*N)+i].birthday.month,&stu[(*N)+i].birthday.day,stu[(*N)+i].address,stu[(*N)+i].tel,stu[(*N)+i].Email);
    			if (0 == flag)
                {
    				k++;
    			}
    		} while (k<(*N)+m);
    	}
    		(*N)=(*N)+m;
    		system("pause");
    }
     
    int main()
    {
        int num,flag=1,N;
        printf("请输入要录入的学生信息个数\n");
        scanf("%d",&N);
        struct Student *stu;
        stu=(struct Student *)malloc(sizeof(struct Student)*N);
        struct Student *stu1;
        stu1=(struct Student *)malloc(sizeof(struct Student)*N);
        while (flag!=0)
        {
            printf("  *************************************************\n\n");
            printf("  *                学生信息管理系统              *\n \n");
            printf("  *************************************************\n\n");
            printf("********************系统功能菜单*********************\n");
            printf("     ----------------------   ---------------------- \n");
            printf("     *********************************************   \n");
            printf("        1.录入学生信息         2.浏览当前信息        \n");
            printf("     *********************************************   \n");
            printf("     *  3.查询学生信息         4.修改学生信息        \n");
            printf("     *********************************************   \n");
            printf("     *  5.删除学生信息         6 增添学生信息        \n");
            printf("     ********************** **********************   \n");
            printf("     ----------------------   ---------------------- \n");
            printf("请选择菜单编号:");
            scanf("%d", &num);
            switch (num)
            {
            case 1:
                insert(stu,N);
                break;
            case 2:
                disp(stu,N);
                break;
            case 3:
                find(stu,N);
                break;
            case 4:
                modify(stu, N);
                break;
            case 5:
                del(stu, &N);
                break;
            case 6:
                add(stu,&N);
                break;
            case 7:
                flag=0;
                printf("即将退出程序!\n");
            default:
                printf("NULL\n");
            }
        }
        return 0;
    }
    

    你插入学生那个输入数据有问题,少了&符号,我帮你修改好了,你看一下。

    点赞 打赏 评论
  • 有问必答小助手 2021-05-26 17:13

    您好,我是有问必答小助手,您的问题已经有小伙伴解答了,您看下是否解决,可以追评进行沟通哦~

    如果有您比较满意的答案 / 帮您提供解决思路的答案,可以点击【采纳】按钮,给回答的小伙伴一些鼓励哦~~

    ps:问答VIP仅需29元,即可享受5次/月 有问必答服务,了解详情>>>https://vip.csdn.net/askvip?utm_source=1146287632

    点赞 打赏 评论

相关推荐 更多相似问题