qq2639785153
qq2639785153
采纳率16.7%
2020-02-26 15:30 阅读 1.0k

为什么 我这代码运行时没输入完就结束?“未完成”????急求!!!!

#include<stdio.h>
#include<stdlib.h>
#include<string.h>
typedef struct stu
{
    char name[10];
    char guan[10];
    char number1[20];
    char number2[20];
    char box[30];
}gs;
typedef struct pgs
{
    gs chat;
    pgs* next;
}*ptgs;
ptgs head=(ptgs)malloc(sizeof(pgs));
int denglu();
int fun1();
int fun2(); 
int fun3();
int fun4();
int app(char *p);//计算字符串长度! 
int main()
{ 
    int i,a;
    head->next=NULL;
    printf("\n\n\t\t\t\t**************************************************************\n");
    printf("\t\t\t\t\t\t\t通讯录管理系统\n");
    printf("\t\t\t\t\t\t\t\t设计者:\n");
    printf("\t\t\t\t**************************************************************\n");
    printf("\t\t\t\t欢迎使用通讯录管理系统!!!!!!\n");
    printf("\t\t\t\t继续请按 1 ,退出请按 0 !\n");
    printf("\t\t\t\t请输入:"); 
    for(i=0;i<2;i=1)
    {
        scanf("%d",&a);
        getchar(); 
        switch(a)
        {
            case 1:denglu();break;
            case 0:break; 
            default:printf("\t\t\t\t请重新输入:");continue;
        }
        break;
    }
    printf("\t\t\t\t系统即将退出!!!");
    printf("\t\t\t\t谢谢使用!!!!!");
 } 
 int denglu()
 {
    int a,i,j,k;
    printf("\n\n");
    printf("\t\t\t\t**************************************************************\n");
    printf("\t\t\t\t\t\t\t>登陆界面<\n"); 
    printf("\n\t\t\t\t\t\t\t登录请输入 1 !\n");
    printf("\t\t\t\t\t\t\t注册请输入 2 !\n");
    printf("\t\t\t\t\t\t\t退出请输入 0 !\n");
    printf("\t\t\t\t请输入:"); 
    for(i=0;i<2;i=1)
    {
        scanf("%d",&a);
        getchar();
        switch(a)
        {
            case 1:fun1();break;
            case 2:fun2();break;
            case 0:break; 
            default:printf("\t\t\t\t请重新输入:");continue;
        }
        break;
    }   
 }
 int fun1()//登陆函数 
{
    FILE *fp;
    int i,k;
    char e[81],f[81],a[81],b[81];
    if((fp = fopen("D:\\w\\hao\\mm.txt","r"))==0)
    {
        printf("\t\t\t\t文件打开失败!!!!");
        denglu(); 
    }
    printf("\n\n\t\t\t\t**************************************************************");
    printf("\n\t\t\t\t\t\t\t<>登陆<>\n");
    printf("\n\t\t\t\t用户名:"); 
    scanf("%s",e);
    printf("\n\t\t\t\t密码:");
    scanf("%s",f); 
    fscanf(fp,"%s %s",a,b);
    fclose(fp);
    if(strcmp(a,e)==0&&strcmp(b,f)==0)
    {
        printf("\n\t\t\t\t登陆成功!!!\n"); 
        fun3();
    }
    else 
    {
        printf("\n\t\t\t\t用户名或密码错误!!\n"); 
        printf("\t\t\t\t重新登陆请按 1 ,退出登陆请按 0 !\n");
        printf("\t\t\t\t请选择:") ; 
        for(i=1;i<2;i=1)
       {
            scanf("%d",&k); 
            getchar();
            switch(k)
            {
                case 1:
                   fun1();break;
                case 0:
                   denglu();break;
                default:
                   printf("\t\t\t\t\t\t输入错误,请重新输入:"); 
                   continue;
            }   
            break;
       }
    }
    system("pause");
}
int fun2()//注册函数 
{
    FILE *fp;
    int i,k;
    fp = fopen("D:\\w\\hao\\mm.txt","w");
    char a[81],b[81],c[81];
    printf("\n\n\t\t\t\t**************************************************************\n");
    printf("\t\t\t\t\t\t\t<>注册界面<>\n");
    printf("\n\t\t\t\t请输入用户名:");
     scanf("%s",a); 
    printf("\n\t\t\t\t请输入密码:");
     scanf("%s",b);
    printf("\n\t\t\t\t请再次输入密码:");
     scanf("%s",c);
    fputs(a,fp);
    fputs("\n",fp);
    fputs(b,fp);
    fclose(fp);
    if(strcmp(b,c)==0)
    {
        printf("\n\t\t\t\t注册成功!\n");
        fun1();
    }
    else
    {
        printf("\t\t\t\t输入的两次密码不一样,注册失败!\n");
        printf("\t\t\t\t重新注册请输入 1 ,退出注册请输入 0 !"); 
        for(i=1;i<2;i=1)
       {
            scanf("%d",&k); 
            getchar();
            switch(k)
            {
                case 1:
                   fun2();break;
                case 0:
                   denglu();break;
                default:
                   printf("\t\t\t\t\t\t输入错误,请重新输入:"); 
                   continue;
            }   
            break;
       }
    }
    system("pause");
}
int fun3()//菜单 
{
    int j;
    char k;
    printf("\n\n\t\t\t\t**************************************************************\n");
    printf("\t\t\t\t\t\t\t<>功能中心<>\n");
    printf("\n\t\t\t\t\t\t「\n");
    printf("\t\t\t\t\t\t\t1.信息录入       \n");
    printf("\t\t\t\t\t\t\t2.信息浏览       \n"); 
    printf("\t\t\t\t\t\t\t3.信息查询       \n"); 
    printf("\t\t\t\t\t\t\t4.信息修改       \n");
    printf("\t\t\t\t\t\t\t5.退出系统       \n");
    printf("\t\t\t\t\t\t\t                 」\n");
    printf("\t\t\t\t请输入相应数字:"); 
    for(j=0;j<2;j=1)
    {
        scanf("%s",&k);
        getchar();
        switch(k)
        {
            case '1':fun4();break;
            case '2':
            case '3':
            case '4':
            case '5':printf("\t\t\t\t系统即将退出!!!\n");break;
            default:printf("\t\t\t\t输入错误!!\n请重新输入:");continue;
        }
    } 
    system("pause");
} 
int fun4()//添加联系人! 
{
    int t,n,a;
    char f='y';
    ptgs p=head,q;
    FILE *V; 
    if((V=fopen("D://information.dat","a+"))==NULL)
    {
        printf("\t\t\t\t文件无法打开!!!\n");
        system("pause");
        fun3(); 
    }
    fprintf(V,"\n\t\t\t\t***************************通讯录列表******************************\n");
    while(p->next)p=p->next;//修改上一个指针域,使其指向现在的节点! 
    while(f!='n'&&f!='N')
    {
        q=(ptgs)malloc(sizeof(pgs));//malloc内存分配函数;内存大小为sizeof(pgs ).
        p->next=q;
        p=q;
        q->next=q;
        printf("\t\t\t\t姓名:");
        scanf("%s",q->chat.name);
        printf("\n\t\t\t\t贯籍:");
        scanf("%s",q->chat.guan);
        printf("\n\t\t\t\t电话号码1:");
        scanf("%s",q->chat.number1);
        do
        {
            n=0;
            if(app(q->chat.number1)!=11)//判断号码是否为十一位电话号码 
            {
                n=1; 
                printf("\t\t\t\t您输入的号码格式不正确!\n");
                printf("\t\t\t\t请重新输入:");
                scanf("%s",q->chat.number1); 
            }
            else
            {
                for(t=0;t<11;t++)
                {
                    if(q->chat.number1[t]<'0'||q->chat.number1[t]>'9')//判断号码是否都为0-9之间的字符 
                    {
                        n=1;
                        printf("\t\t\t\t您输入的号码格式不正确!\n");
                        printf("\t\t\t\t请重新输入:");
                        scanf("%s",q->chat.number1);
                        break;
                    }
                }
            }
         }while(n);
         printf("\n\t\t\t\t电话号码2:");
         scanf("%s",q->chat.number2); 
         do
         {
             n=0;
             if(app(q->chat.number2)!=11)
             {
                 n=1; 
                 printf("\t\t\t\t您输入的号码格式不正确!\n");
                 printf("\t\t\t\t请重新输入:");
                 scanf("%s",q->chat.number2); 
             }
             else
             {
                 for(t=0;t<11;t++)
                 {
                     if(q->chat.number2[t]<'0'||q->chat.number2[t]>'9')
                     {
                         n=1;
                         printf("\t\t\t\t您输入的号码格式不正确!\n");
                         printf("\t\t\t\t请重新输入:");
                         scanf("%s",q->chat.number2);
                         break;
                     }
                 }
             }
         }while(n);
         printf("\n\t\t\t\t邮箱:"); 
         scanf("%s",p->chat.box); 
         do
         {
            a=0;
            for(t=0;p->chat.box[t]='\0';t++)
            {
                if(p->chat.box[t]=='@')
                   a++;
             }
             if(a!=1);
             {
                printf("\n\t\t\t\t输入的邮箱格式不合理!\n");
                printf("\t\t\t\t请重新输入:");
                scanf("%s",p->chat.box); 
             }
         }while(a!=1);
         fprintf(V,"\t\t\t%s\t%s\t%s\t%s\t%s",p->chat.name,p->chat.guan,p->chat.number1,p->chat.number2,p->chat.box);
         p=p->next;
         printf("\n\t\t\t\t是否继续录入?(Y/N)!\n");
         scanf("\t\t\t\t%c",&f);
    }
    fclose(V);
    system("pause");
    fun3();
}
int app(char *p)
{
    int count,k;
    k=0;
    while((p[k] = getchar()) != '\n')
    {
        k++;
    }
    p='\0';
    count=0;
    for(k=0;p[k]!='\0';k++)
    {
        count++;    
    }
    return count;
}
  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享

1条回答 默认 最新

  • FlyToFarAway FlyToFarAway 2020-02-27 10:52

    for(i=0;i<2;i=1)//这里错了吧?改成while循环试试
    {
    scanf("%d",&a);
    getchar();
    switch(a)
    {
    case 1:fun1();break;
    case 2:fun2();break;
    case 0:break;
    default:printf("\t\t\t\t请重新输入:");continue;
    }
    break;
    }

    }

    点赞 评论 复制链接分享

相关推荐