标题:在这个程序中语句system("cls");作用
只看楼主
smbb0079
Rank: 1
等 级:新手上路
帖 子:4
专家分:0
注 册:2012-11-12
结帖率:50%
已结贴  问题点数:20 回复次数:3 
在这个程序中语句system("cls");作用
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
struct student
{
    int num;
    char name[20];
    char sex;
    int age;
    char beizhu[1000];

};

void main()
{
    int pwsave=123456,pwscf1,xiu;
    int count=0,i,gg=0;
    char jin;
    struct student stu[10];
    FILE * fp;         
       fp=fopen("d:\\课程设计成果\\cg\\学生信息.txt","w+");
       {
         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);
       }

    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");
                scanf("%c",&jin);
                {
                    switch(jin)
                    {
                        case 'a':
                        {
                           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;
                           }
                        }break;

                        case 'b':
                        {
                           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();
                        }break;

                        case 'c':
                        {
                           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);
                           printf("按任意键继续操作");
                           getchar();
                           getchar();
                        }break;

                        case 'd':
                        {
                           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();
                           }
                        }break;

                        case 'e':
                        {
                           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();
                               }
                        }break;

                        case 'f':
                        {
                            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;
                        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);
        }
    }
}
搜索更多相关主题的帖子: void include system count 
2012-11-13 14:50
wp231957
Rank: 16Rank: 16Rank: 16Rank: 16
来 自:神界
等 级:版主
威 望:422
帖 子:13681
专家分:53296
注 册:2012-10-18
得分:7 
调用 dos 清屏命令  ?
没实际测试  猜的

DO IT YOURSELF !
2012-11-13 14:52
zklhp
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
来 自:china
等 级:贵宾
威 望:254
帖 子:11485
专家分:33241
注 册:2007-7-10
得分:7 
以下是引用wp231957在2012-11-13 14:52:28的发言:

调用 dos 清屏命令  ?
没实际测试  猜的

就这功能 而且这种写法不可移植 因为*nix里没cls罢 是clear
2012-11-13 15:06
lwb603569640
Rank: 6Rank: 6
等 级:侠之大者
威 望:2
帖 子:283
专家分:436
注 册:2012-11-9
得分:7 
以下是引用zklhp在2012-11-13 15:06:58的发言:


就这功能 而且这种写法不可移植 因为*nix里没cls罢 是clear

可以用宏指令加条件编译  在不同平台选择不同的。。

自由、民主、宪政!
2012-11-13 16:26



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-386897-1-1.html




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

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