| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 398 人关注过本帖
标题:不知道我的程序问题出在什么地方,求高人指点
只看楼主 加入收藏
smbb0079
Rank: 1
等 级:新手上路
帖 子:4
专家分:0
注 册:2012-11-12
结帖率:50%
收藏
 问题点数:0 回复次数:1 
不知道我的程序问题出在什么地方,求高人指点
#include<string.h>
#include<stdio.h>
struct student
{
    int num;
    char name[20];
    char sex;
    int age;
    char beizhu[1000];

};

void addDate()
{
      system("cls");
      for(i=count;i<10;i++)
       {
          printf("请输入学生%d的信息:学号、姓名、性别、年龄、备注\n",(count+1));
          scanf("%d %s %c %d %s",&stu[i].num,stu[i].name,&stu[i].sex,&stu[i].age,stu[i].beizhu);
          count++;
          printf("是否继续输入?Y/N\n");
          getchar();
          scanf("%c",&jin);
          getchar();
          if(jin!='Y')
          break;
        }
}
                                                                                                                                                                                                                                                                                                                                                                        
void listdate()
{
    system("cls");
    for(i=0;i<count;i++)
      {
        printf("学号:%d\n姓名:%s\n性别:%c\n年龄:%d\n备注:%s\n",stu[i].num,stu[i].name,stu[i].sex,stu[i].age,stu[i].beizhu);
          }
    printf("按任意键继续操作");
    getchar();
    getchar();
}

void keepDate()
{
                           system("cls");
                           FILE * fp;
                           fp=fopen("学生信息","w+");
                           fprintf(fp,"%d\n",count);//用格式化方式读入文件
                           for(i=0;i<count;i++)
                           {
                              fprintf(fp,"学号:%d\n姓名:%s\n性别:%c\n年龄:%d\n备注:%s\n",
                              stu[i].num,stu[i].name,stu[i].sex,stu[i].age,stu[i].beizhu);
                           }
                           printf("保存成功\n");
                           fclose(fp);//用fclose函数关闭数据文件
                           printf("按任意键继续操作");
                           getchar();
                           getchar();
                        }
void serchDate()
 {
                            system("cls");
                            int x;
                            printf(" (1).按学号查询\n (2).按姓名查询\n (3).按性别查询\n (4).按年龄查询\n");
                            printf("请选择:");
                            scanf("%d",&x);
                            if(x==1)
                            {
                              system("cls");
                              int b1;
                              printf("请输入学号:");
                              scanf("%d",&b1);
                              for(i=0;i<count;i++)
                              {
                                if(b1==stu[i].num)
                                 break;
                              }
                                if(i>=count)
                                  {printf("查无此人\n");printf("按任意键继续操作");getchar();getchar();}
                                else
                                  {printf("学号:%d\n姓名:%s\n性别:%c\n年龄:%d\n备注\n",
                                  stu[i].num,stu[i].name,stu[i].sex,stu[i].age,stu[i].beizhu);
                                printf("按任意键继续操作");getchar();getchar();}
                            }
                            else if(x==2)
                            {
                                system("cls");
                                getchar();
                                int j=0;
                                char name1[20];
                                printf("请输入姓名:");
                                gets(name1);
                                for(i=0;i<count;i++)
                                {
                                if(strcmp(name1,stu[i].name)==0)
                                  {printf("学号:%d\n姓名:%s\n性别:%c\n年龄:%d\n备注%s\n",
                                  stu[i].num,stu[i].name,stu[i].sex,stu[i].age,stu[i].beizhu);
                                j=1;printf("按任意键继续操作");getchar();getchar();}
                                }
                                if(j==0)
                                  {printf("查无此人\n");printf("按任意键继续操作");getchar();getchar();}
                            }
                            else if(x==3)
                            {
                               system("cls");
                               char sex1;
                               getchar();
                               printf("请输入性别:");
                               scanf("%c",&sex1);
                               for(i=0;i<count;i++)
                               {
                               if(sex1==stu[i].sex)
                                 {printf("学号:%d\n姓名:%s\n性别:%c\n年龄:%d\n备注%s\n",
                                 stu[i].num,stu[i].name,stu[i].sex,stu[i].age,stu[i].beizhu);
                                printf("按任意键继续操作");getchar();getchar();}
                               }
                            }
                            else if(x==4)
                            {
                               system("cls");
                               int y;
                               printf("请输入年龄:");
                               scanf("%d",&y);
                               for(i=0;i<count;i++)
                               {
                               if(y==stu[i].age)
                                 {printf("学号:%d\n姓名:%s\n性别:%c\n年龄:%d\n备注%s\n",
                                 stu[i].num,stu[i].name,stu[i].sex,stu[i].age,stu[i].beizhu);
                                printf("按任意键继续操作");getchar();getchar();}
                               }
                            }
                            else
                               {printf("无此项操作\n");printf("按任意键继续操作");getchar();getchar();}
                        }break;

void deleteDate()
{
                           system("cls");
                           int xuehao,i1,flag=0;
                           printf("请输入要删除学生的学号:\n");
                           scanf("%d",&xuehao);
                           for(i=0;i<count;i++)
                           {
                             if(xuehao==stu[i].num)
                              {
                                 flag=1;
                                 for(i1=i;i1<count-1;i1++)
                                 {
                                    stu[i1]=stu[i1+1];
                                 }
                              }
                           }
                           if(flag==0)
                               {
                                   printf("查无此人\n");
                                   printf("按任意键继续操作");
                                   getchar();
                                   getchar();
                               }
                           if(flag==1)
                           {
                              count=count-1;
                              printf("删除成功\n");
                              printf("按任意键继续操作");
                              getchar();
                              getchar();
                           }
                        }

void updateDate()
{
                           system("cls");
                           char n1[20],c2;
                           int  c1,k;
                           printf("请输入密码:\n");
                           scanf("%d",&pwscf1);
                           if(pwscf1==pwsave)
                           {
                              printf("请输入要修改学生的学号:");
                              scanf("%d",&c1);
                              for(i=0;i<count;i++)
                              {
                                 if(stu[i].num==c1)
                                 {
                                    while(1)
                                    {
                                       if(k==5)
                                           break;
                                       system("cls");
                                       printf("1.修改姓名\n");
                                       printf("2.修改年龄\n");
                                       printf("3.修改性别\n");
                                       printf("4.修改备注\n");
                                       printf("5.退出\n");
                                       printf("请输入你的选择:");
                                       scanf("%d",&k);
                                       switch(k)
                                       {
                                       case 1:system("cls");
                                              printf("请输入新姓名:");
                                              scanf("%s",n1);
                                              strcpy(stu[i].name,n1);break;//字符串复制函数
                                       case 2:system("cls");
                                              printf("请输入新年龄:");
                                              scanf("%d",&c1);
                                              stu[i].age=c1;break;
                                       case 3:system("cls");
                                              printf("请输入新性别:");
                                              getchar();
                                              scanf("%c",&c2);
                                              stu[i].sex=c2;break;
                                       case 4:system("cls");
                                              printf("请输入新备注:");
                                              scanf("%s",n1);
                                              strcpy(stu[i].beizhu,n1);break;
                                       case 5:system("cls");break;
                                       default:printf("无此项操作\n");
                                       }
                                    }
                                 }
                              }
                              printf("按任意键继续操作");
                              getchar();
                              getchar();
                           }
                           else
                               {
                                   printf("密码错误\n");
                                   printf("按任意键继续操作");
                                   getchar();
                                   getchar();
                               }
                        }

void main()
{
    FILE*fp;
     int pwsave=123456,pwscf1,xiu;
    int count=0,i,gg=0;
    char jin;
    struct student stu[10];
       fp=fopen("学生信息","r+");//将fopen函数返回值赋给指针变量fp
       {
         fscanf(fp,"%d\n",&count);
         for(i=0;i<count;i++)
         {
            fscanf(fp,"学号:%d\n姓名:%s\n性别:%c\n年龄:%d\n备注:%s\n",&stu[i].num,stu[i].name,&stu[i].sex,&stu[i].age,stu[i].beizhu);//用格式化方式写入文件
         }
        fclose(fp);//用fclose函数关闭数据文件
       }

    printf("请输入密码\n");xiu=4;
    while(scanf("%d",&pwscf1))
    {
       if(pwscf1==pwsave)
        {
            while(1)
            {
                system("cls");
                printf("a   学生基本信息录入\n");
                printf("b   学生基本信息显示\n");
                printf("c   学生基本信息保存\n");
                printf("d   学生基本信息删除\n");
                printf("e   学生基本信息修改(要求先输入密码)\n");
                printf("f   学生基本信息查询\n");
                printf("g   退出程序\n");
                printf("请选择项目\n");
                scanf("%c",&jin);
                {
                    switch(jin)
                    {
                       case 'a':
                            addDate();
                             break;
                       case 'b':
                           listDate();
                               break;
                       case'c':
                           keepDate();
                           break;
                       case'd':
                           daleteDate();
                           break;
                       case'e':
                           updateDate();
                           break;
                       case'f':
                           searchDate();
                           break;
                       case'g':
                         {gg=1;break;}
                    }
                }
                if(gg==1)
                    break;
            }
            if(gg==1)
                break;

        }
        else
        {
            system("cls");
            xiu--;
            if(xiu==0)
                break;
            printf("密码错误,请重新输入,您还有%d次机会\n",xiu);
        }
    }
}

问题如图

对一个有N个学生的班级,通过该系统实现对该班级学生的基本信息进行录入、显示、修改、删除、保存等操作的管理。
二、功能要求:
1、本系统采用一个包含N个数据的结构体数组,每个数据的结构应当包括:学号、姓名、性别、年龄、备注。
2、本系统显示这样的菜单:
请选择系统功能项:
a.    学生基本信息录入
b.    学生基本信息显示
c.    学生基本信息保存
d.    学生基本信息删除
e.    学生基本信息修改(要求先输入密码)
f.    学生基本信息查询
(1)    按学号查询
(2)    按姓名查询
(3)    按性别查询
(4)    按年龄查询
g. 退出系统
3、执行一个具体的功能之后,程序将重新显示菜单。
4、将学生基本信息保存到文件中。
5、进入系统之前要先输入密码。


搜索更多相关主题的帖子: include system count 
2012-11-12 15:56
azzbcc
Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19
来 自:江西财经大学
等 级:贵宾
威 望:81
帖 子:3293
专家分:12919
注 册:2012-11-4
收藏
得分:0 
调的很无语。。。。。。
n个undeclared identifier
楼主不能百度一下这句话的意思么?建议再了解一下 全局变量

另外,有3个函数名拼写错误
还有system 的头文件。。。



[fly]存在即是合理[/fly]
2012-11-12 16:34
快速回复:不知道我的程序问题出在什么地方,求高人指点
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.021224 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved