| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 491 人关注过本帖
标题:极力求助啊!有一处错误,找不出来!
只看楼主 加入收藏
lianye
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2008-7-7
收藏
 问题点数:0 回复次数:4 
极力求助啊!有一处错误,找不出来!
#define N 3
#define M 100
#ifndef STRU_STUDENT
#define STRU_STUDENT
typedef struct student
{     char   phone[20];
      char   name[15];
      char   adress[50];
      char   email[30];
      char   bir[3];
}STU;
#endif
extern STU stu[M];
#include "stdio.h"
#include "string.h"
#include "math.h"
#include "ctype.h"
#include "stdlib.h"
#include "conio.h"
void key()
  {     int i=1;
      char password[20];

      while(1)
      {
      printf("input the key number:");
      gets(password);
      if(strcmp(password,"lsy0221")!=0)
       printf("wrong!press any key to continue!\n");
       else break;
     getch();
     i++;
     if(i==3)
     exit(0);
          }
  }
void menu()
{
 printf("\n---------------welcome to contact system------------------\n");
 printf("  1.Add\n");
 printf("  2.Delete\n");
 printf("  3.Mondify\n");
 printf("  4.Search\n");
 printf("  5.Exit");
 printf("\n---------------welcome to contact system------------------\n");
 printf("please choice:");
}
void add()
{
 int i=0,k,sum,m=0,flag=0,n=0,flag1,flag2;
   char ch;
   FILE *fp;
   STU stu1[M/2];
   if((fp=fopen("e:\\student.dat","a+"))==NULL)
   {  printf("open file error!\n");
      exit(0);
   }
   for(i=0;fread(&stu1[i],sizeof(STU),1,fp)!=0;i++);
  n=i;
   fclose(fp);
   i=0;
   while(1)
   { printf ("\nplease input number%d's information:\n",i+1);
      do
      {
         flag=0;
         printf("phone: ");
         scanf("%s",stu[i].phone);
         for(k=i-1;k>=0;k--)
            if(strcmp(stu[k].phone,stu[i].phone)==0)
            { printf("the phone number is exist,enter again!\n");
               flag=1;
           break;
            }
         for(k=0;k<n;k++)
            if(strcmp(stu1[k].phone,stu[i].phone)==0)
            { printf("the num is exist,enter again!\n");
               flag=1;
               break;
            }
         sum=strlen(stu[i].phone);
         for(k=0;k<sum;k++)
            if(!isdigit(stu[i].phone[k]))
            {  printf("num error,enter again!\n");
               flag=1;
               break;
            }
      }while(flag);
      do
      {
         flag=0;
         printf("name: ");
         scanf("%s",stu[i].name);
         sum=strlen(stu[i].name);
         for(k=0;k<sum;k++)
        if(!isalpha(stu[i].name[k]))
            {  printf("name error,enter again!\n");
               flag=1;
               break;
            }
      }while(flag);
      do
      {
         flag=0;
         printf("email: ");
         scanf("%s",stu[i].email);
         for(k=i-1;k>=0;k--)
            if(strcmp(stu[k].email,stu[i].email)==0)
            { printf("the email adress is exist,enter again!\n");
               flag=1;
           break;
            }
         for(k=0;k<n;k++)
            if(strcmp(stu1[k].email,stu[i].email)==0)
            { printf("the email adress is exist,enter again!\n");
               flag=1;
               break;
            }
         sum=strlen(stu[i].email);
         for(k=0;k<sum;k++)
            if(!isdigit(stu[i].email[k]))
            {  printf("num error,enter again!\n");
               flag=1;
               break;
            }
      }while(flag);
      do
      {
       printf("his or her birthday:\n");
       printf("Year:");
       scanf("%d",&stu[i].bir[0]);
       if(stu[i].bir[0]%4==0&&stu[i].bir[0]%100!=0||stu[i].bir[0]%400==0)
       flag=1;
       else flag=0;
       do
         {
          flag1=0;
          printf("Month:");
          scanf("%d",&stu[i].bir[1]);
          while(stu[i].bir[1]>12||stu[i].bir[1]<0)
          {
           printf("wrong!please input again!\n");
           flag1=1;
           break;
          }while(flag1);

     }while(flag);
       do
         {
          printf("Day:");
          scanf("%d",&stu[i].bir[2]);
          switch(stu[i].bir[1])
           {
            case 1:{if(stu[i].bir[2]>0&&stu[i].bir[2]<=31)
            flag2=1;
            else flag2=0;
            break;}
            case 2:{if(flag==1&&stu[i].bir[2]==29)flag2=1;
                    else if(stu[i].bir[2]>0&&stu[i].bir[2]<=28)flag2=1;
                         else flag2=0;break;}
            case 3:{if(stu[i].bir[2]>0&&stu[i].bir[2]<=31)
            flag2=1;
            else flag2=0;
            break;}
            case 4:if(stu[i].bir[2]>0&&stu[i].bir[2]<=30)flag2=1;
                   else flag2=0;break;
            case 5:{if(stu[i].bir[2]>0&&stu[i].bir[2]<=31)
            flag2=1;
            else flag2=0;
            break;}
            case 6:if(stu[i].bir[2]>0&&stu[i].bir[2]<=30)flag2=1;
                   else flag2=0;break;
            case 7:{if(stu[i].bir[2]>0&&stu[i].bir[2]<=31)
            flag2=1;
            else flag2=0;
            break;}
            case 8:{if(stu[i].bir[2]>0&&stu[i].bir[2]<=31)
            flag2=1;
            else flag2=0;
            break;}
            case 9:if(stu[i].bir[2]>0&&stu[i].bir[2]<=30)flag2=1;
                   else flag2=0;break;
            case 10:{if(stu[i].bir[2]>0&&stu[i].bir[2]<=31)
            flag2=1;
            else flag2=0;
            break;}
            case 11:if(stu[i].bir[2]>0&&stu[i].bir[2]<=30)flag2=1;
                   else flag2=0;break;
            case 12:{if(stu[i].bir[2]>0&&stu[i].bir[2]<=31)
            flag2=1;
            else flag2=0;
            break;}
           }
        while(flag2==0)
            {
             printf("wrong!please input again!\n");
              flag2=1;
              break;
            }
         }while(flag2);
      }while(flag);
      printf("adress:");
      scanf("%s",stu[i].adress);

      m++;
      i++;
      printf("continue to create?(yes--y or Y,no--others)\n");
      getchar();
      scanf("%c",&ch);
      if(ch!='y'&&ch!='Y') break;
   }

   if((fp=fopen("e:\\student.dat","a"))==NULL)
   {  printf("open error!\n");
      exit(0);
   }
   for(i=0;i<m;i++)
      if(fwrite(&stu[i],sizeof(stu[0]),1,fp)!=1)
         printf("file write error\n");
   fclose(fp);
}


void delete()
{
 void delete_one();
 void delete_all();
 int m;
 printf("delete one or delete all,please choice 1 or 2");
 scanf("%d",&m);
 switch(m)
 {
  case 1:delete_one();break;
  case 2:delete_all();break;
     }
}
void delete_one()
{
 int i,j,flag,n;
   char s[15];
   char ch;
   FILE *fp;
   if ((fp=fopen("e:\\student.dat","r"))==NULL)
   {
      printf("The error file");
      exit(0);
   }
   for(i=0;fread(&stu[i],sizeof(STU),1,fp)!=0;i++)
      n=i;
   fclose(fp);
   do
   {
      printf("\nplease input the person's name who you want to delete:");
      scanf("%s",s);
      for(flag=1,i=0;flag&&i<n;i++)
      {
         if(strcmp(s,stu[i].name)==0)
         {
            printf("the deleted record is:\n");
            printf("%12s%12s%12s%12s%12s\n","Name","Phone","Email","Adress",
"Birthday");
            printf("%12s%12s%12s",stu[i].name,stu[i].phone,stu[i].adress);
            for(j=0;j<N;j++)
               printf("%3d",stu[i].bir[j]);
            printf("\n");
            if(i==n-1)
            {
               n--;
               flag=0;
            }
            else
            {
               for(j=i;j<n-1;j++)
                  stu[j]=stu[j+1];
               flag=0;
               n--;
            }
         }
      }
      if (flag==0)
         printf("\n the person has deleted\n");
      else
         printf("\n The person is not exit\n");
      printf("continue to delete?(yes-y,no-others)\n");
      getchar();
      ch=getchar();
   }while(ch=='y'||ch=='Y');
   if((fp=fopen("e:\\student.dat","w"))==NULL)
   {
      printf("open file error!\n");
      exit(0);
   }
   for(i=0;i<n;i++)
      fwrite(&stu[i],sizeof(struct student),1,fp);
   fclose (fp);
}

void delete_all()
{
    char ch1;
   FILE *fp;
   if((fp=fopen("e:\\student.dat","w"))==NULL)
   { printf("open file error!\n");
      exit(0);
   }
   printf("delete all,really?(yes--y or Y,no--others)\n");
   getchar();
   scanf("%c",&ch1);
   if(ch1=='y'||ch1=='Y')
      printf("delete all is successful!\n");
   printf("press any key to back menu...\n");
   getch();
   fclose(fp);
}


void mondify()
{
 int i,j,flag,n,flag1,flag2;
   char ch,ch1,num[15];
   FILE *fp;
   flag=1;
   printf("input the person's name to be modified:");
   scanf("%s",num);
   if((fp=fopen("e:\\student.dat","r"))==NULL)
   { printf("the file can not open\n");
      exit(0);
   }
   for(i=0;fread(&stu[i],sizeof(STU),1,fp)!=0;i++);
   n=i;
   fclose(fp);


      for(i=0;i<n;i++)
         if(strcmp(num,stu[i].name)==0)
         { flag=0;
            printf("the modified record is:\n");
            printf("%12s%12s%12s%12s%12s\n","Name","Phone","Email","Adress","Birthday");
            printf("%12s%12s%12s%12s",stu[i].name,stu[i].phone,stu[i].email,stu[i].adress);
            for(j=0;j<N;j++)
               printf("%3d",stu[i].bir[j]);
            printf("\n");
            while(1)
             {
              printf("do you modify the name?\n");
              printf("please input y or n:\n");
              ch=getch( );
              if(ch=='y'||ch=='Y')
              {  printf("input the name:\n");
                 scanf("%s",stu[i].name);
              }else break;
             }
            while(1)
              {
               printf("do you mldify the phone?\n");
               printf("input y or n:\n");
               ch=getch();
               if(ch=='y'||ch=='Y')
               {  printf("input a new phone number:\n") ;
                  getchar();
                  scanf("%c",&stu[i].phone);
               }else break;
              }
            while(1)
              {
                printf("do you modify the email adress?\n");
                printf("please input y or n:\n");
                ch=getch( );
                if(ch=='y'||ch=='Y')
               {  printf("input a new email adress:\n");
                  scanf("%s",stu[i].email);
              }else break;
             }
            while(1)
              {
                printf("do you mldify the adress?\n");
                printf("input y or n:\n");
                ch=getch();
                if(ch=='y'||ch=='Y')
                {  printf("input a new adress:\n") ;
                   getchar();
                   scanf("%s",&stu[i].adress);
                }else break;
               }
            while(1)
             {
              printf("do you want to modify the birthday?\n");
              printf("input y or n:\n");
              ch=getch();
               if(ch=='y'||ch=='Y')
               {
                do
      {
       printf("his or her birthday:\n");
       printf("Year:");
       scanf("%d",&stu[i].bir[0]);
       if(stu[i].bir[0]%4==0&&stu[i].bir[0]%100!=0||stu[i].bir[0]%400==0)
       flag=1;
       else flag=0;
       do
         {
          flag1=0;
          printf("Month:");
          scanf("%d",&stu[i].bir[1]);
          while(stu[i].bir[1]>12||stu[i].bir[1]<0)
          {
           printf("wrong!please input again!\n");
           flag1=1;
           break;
      }

     }while(flag1);
       do
         {
          printf("Day:");
          scanf("%d",&stu[i].bir[2]);
          switch(stu[i].bir[1])
           {
            case 1:{if(stu[i].bir[2]>0&&stu[i].bir[2]<=31)
            flag2=1;
            else flag2=0;
            break;}
            case 2:{if(flag==1&&stu[i].bir[2]==29)flag2=1;
                    else if(stu[i].bir[2]>0&&stu[i].bir[2]<=28)flag2=1;
                         else flag2=0;break;}
            case 3:{if(stu[i].bir[2]>0&&stu[i].bir[2]<=31)
            flag2=1;
            else flag2=0;
            break;}
            case 4:if(stu[i].bir[2]>0&&stu[i].bir[2]<=30)flag2=1;
                   else flag2=0;break;
            case 5:{if(stu[i].bir[2]>0&&stu[i].bir[2]<=31)
            flag2=1;
            else flag2=0;
            break;}
            case 6:if(stu[i].bir[2]>0&&stu[i].bir[2]<=30)flag2=1;
                   else flag2=0;break;
            case 7:{if(stu[i].bir[2]>0&&stu[i].bir[2]<=31)
            flag2=1;
            else flag2=0;
            break;}
            case 8:{if(stu[i].bir[2]>0&&stu[i].bir[2]<=31)
            flag2=1;
            else flag2=0;
            break;}
            case 9:if(stu[i].bir[2]>0&&stu[i].bir[2]<=30)flag2=1;
                   else flag2=0;break;
            case 10:{if(stu[i].bir[2]>0&&stu[i].bir[2]<=31)
            flag2=1;
            else flag2=0;
            break;}
            case 11:if(stu[i].bir[2]>0&&stu[i].bir[2]<=30)flag2=1;
                   else flag2=0;break;
            case 12:{if(stu[i].bir[2]>0&&stu[i].bir[2]<=31)
            flag2=1;
            else flag2=0;
            break;}
           }
        while(flag2==0)
            {
             printf("wrong!please input again!\n");
              flag2=1;
              break;
            }
         }while(flag2);
      }while(flag);
               }
               else break;
             }
      if(flag)
         printf("The person's name you input is error!\n");
      printf("continue to modify?(yes--y or Y,no--others)\n");
      getchar( );
      ch1=getchar( );
   }while(ch1=='y'||ch1=='Y');
   rewind(fp);
   if((fp=fopen("e:\\student.dat","w"))==NULL)
   { printf("open file error!\n");
      exit(0);
   }
   for(i=0;i<n;i++)
      fwrite(&stu[i],sizeof(struct student),1,fp);
   fclose(fp);
   }

void search()
{
 int flag,i,j,n,flag1;
   FILE *fp;
   char ch,str[10];
   if((fp=fopen("e:\\student.dat","r"))==NULL)
   {
      printf("Open file failed!\n");
      exit(0);
   }
   for(i=0;fread(&stu[i],sizeof(STU),1,fp)!=0;i++);
   n=i;
   do
   {
      flag1=0;
      printf("Please enter the name!\n");
      scanf("%s",str);
      for(i=0;i<n;i++)
         if(strcmp(stu[i].name,str)==0)
         {
            flag1=1;
            printf("%12s%12s%12s%12s%12s\n","Name","Phone","Email","Adress","Birthday");
            printf("%12s%12s%12s%12s",stu[i].name,stu[i].phone,stu[i].email,stu[i].adress);
            for(j=0;j<N;j++)
               printf("%3d",stu[i].bir[3]);
            printf("\n");
         }
         if(flag1==0)
            printf("this record doesn't exist!\n");
         printf("You need continue to input the name?(yes-y or Y,no-others)\n");
         getchar();
         scanf("%c",&ch);
         if((ch=='Y')||(ch=='y'))
            flag=1;
         else
            flag=0;
   }while(flag);
   fclose(fp);
}

void main()
{

 int n;
 menu();
 scanf("%d",&n);
  switch(n)
  {
      case 1:key();add();break;
      case 2:key();delete();break;
      case 3:key();mondify();break;
      case 4:search();break;
      case 5:break;
      default:printf("choice error!\n");
  }
}
搜索更多相关主题的帖子: password include number email 
2008-07-07 09:06
mqh21364
Rank: 1
等 级:新手上路
帖 子:642
专家分:0
注 册:2008-2-28
收藏
得分:0 
大哥错误提示发出来啊!这么长谁有心情一行一行去看啊?

前不见古人,后不见来者。念天地之悠悠,独怆然而涕下。
2008-07-07 09:24
界水乘风
该用户已被删除
收藏
得分:0 
提示: 作者被禁止或删除 内容自动屏蔽
2008-07-07 09:39
天空飘云
Rank: 1
等 级:新手上路
帖 子:16
专家分:0
注 册:2008-7-5
收藏
得分:0 
[bo][un]界水乘风[/un] 在 2008-7-7 09:39 的发言:[/bo]

把第13行的extern去掉试试看。

   去了就没错了   
#define N 3
#define M 100
#ifndef STRU_STUDENT
#define STRU_STUDENT
typedef struct student
{     char   phone[20];
      char   name[15];
      char   adress[50];
      char   email[30];
      char   bir[3];
}STU;
#endif
 STU stu[M];
#include "stdio.h"
#include "string.h"
#include "math.h"
#include "ctype.h"
#include "stdlib.h"
#include "conio.h"
就可以运行    而把STU放到12行就有26个错误了
}STU;
#endif STU stu[M];
#include "stdio.h"
#include "string.h"
请教何故
2008-07-07 16:21
界水乘风
该用户已被删除
收藏
得分:0 
回复 4# 天空飘云 的帖子
提示: 作者被禁止或删除 内容自动屏蔽
2008-07-07 16:46
快速回复:极力求助啊!有一处错误,找不出来!
数据加载中...
 
   



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

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