当前位置: 代码迷 >> C语言 >> 下面程序用'*'怎么回显
  详细解决方案

下面程序用'*'怎么回显

热度:331   发布时间:2008-04-28 13:56:27.0
下面程序用'*'怎么回显
#include<stdio.h>
密码用‘*’回显,帮忙修改一下吧!谢谢了!
#include<string.h>
void main()
{
    int i=0,j=0,k=0,z=0,n=0;
    char name1[10],name2[6]="happy",s1[10],s2[4]="abc";
     printf("please input your name:");
     gets(name1);
     
     while(strcmp(name1,name2)!=0&&j<=1)
     {
         printf("input again:");
         gets(name1);
         
         j++;
     }
     if(strcmp(name1,name2)!=0)
         printf("over");
     
     else
     {
         printf("please input your password:");
         while((s1[i]=getchar())!='\n')
         
         {    putchar('*');
            
            
            i++;
         }
         s1[i]='\0';
         while(strcmp(s1,s2)!=0&&z<=1)
         {n=0;
             printf("input again:");
             while((s1[n]=getchar())!='\n')
             {
                putchar('*');
                 n++;
             }
             s1[n]='\0';
             z++;
         }
             if(strcmp(s1,s2)==0)
            
                 printf("pass");
               
            
             else
                 printf("fail");
         
     }
}
----------------解决方案--------------------------------------------------------
调试出来了
#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
    int i=0,j=0,k=0,z=0,n=0;
    char name1[10],name2[6]="happy",s1[10],s2[4]="abc";
     printf("please input your name:");
     gets(name1);
    
     while(strcmp(name1,name2)!=0&&j<=1)
     {
         printf("input again:");
         gets(name1);
        
         j++;
     }
     if(strcmp(name1,name2)!=0)
         printf("over");
    
     else
     {
         printf("please input your password:");
         while((s1[i]=getch())!='\r')
        
         {    putchar('*');
            
            
            i++;
         }
         s1[i]='\0';
         while(strcmp(s1,s2)!=0&&z<=1)
         {n=0;
             printf("input again:");
             while((s1[n]=getch())!='\r')
             {
                putchar('*');
                 n++;
             }
             s1[n]='\0';
             z++;
         }
             if(strcmp(s1,s2)==0)
            
                 printf("pass");
                
            
             else
                 printf("fail");
        
     }
}
----------------解决方案--------------------------------------------------------
  相关解决方案