您的位置:程序门 -> c/c++ ->



写一段代码完成如下功能(急求)


[收藏此页] [打印本页]选择字色:背景色:字体:[][][]


写一段代码完成如下功能(急求)
发表于:2007-06-10 17:36:59 楼主
从键盘输入一串字符,输入的信息打印出来全部为*号,当输入回车键的时候跳转道另一个函数show();

1.能判断是否输入了6个字符,少输入或者多输入都报错;
2.能判断输入的是否为123456,若不是则提示错误,然后提示重新输入;
3.输入正确以后跳转道show()函数
发表于:2007-06-10 18:26:271楼 得分:0
#include <stdio.h>
#include <conio.h>
#include <string.h>
#include <stdlib.h>

void         show(   )
{
puts( "\nshow!\n ");
}

int   main()
{
        char     key[8]= "123456\r ";
        char     pw[8]={0};
        int       i;
bool     match=false;
while(   match==false   )
{
i=0;
puts( "please   input   your   password: ");
while((pw[i++]=getch())!= '\r ')
putchar( '* ');
if(!strcmp(pw,key))
{
show(   );
match=true;
}
else  
puts( "\nwrong!\n ");
}
        system( "pause ");
        return   0;
}
发表于:2007-06-10 18:33:332楼 得分:0
#include   <conio.h>
#include   <stdio.h>
char*   getpsw(char   psw[32])
{
        char   temp[32];
        for(int   i=0;i <31;i++)
        {
                char   c=getch();
                if(c==8   &&   i   !=   0)
                {
                        i=i-2;
                        psw[i+1]=0;
                        temp[i+1]=0;
                        printf( "%c ",13);
                        printf( "                                                                 ");
                        printf( "%c ",13);
                        printf( "%s ",temp);
                        continue;
                }else   if(c==13)
                {
                        psw[i]=0;
                        printf( "%c ", '\n ');
                        return   psw;
                }
                psw[i]=c;
                temp[i]= '* ';
                printf( "%c ", '* ');
        }
        printf( "喂,你的密码有那么长吗,还不回车?后面的输入无效了. ");
        psw[31]=0;
        return   psw;
}
void   show(char*   psw)
{
        printf( "%s\n ",psw);
}
int   main()
{
        char   psw[32];
        while(1)
        {
                getpsw(psw);
                if(strlen(psw) <6   ¦ ¦   strlen(psw)> 6)
                        printf( "密码长度错误,重新输入\n ");
                else   if(strcmp(psw, "123456 ")!=0)
                        printf( "密码错误,重新输入\n ");
                else
                        break;
        }
        show(psw);
        return   0;
}
发表于:2007-06-10 18:35:143楼 得分:0
#include   <stdio.h>
#include   <stdlib.h>
#include   <string.h>
#include   <conio.h>

void   show()
{
      printf( "good   job,   you 've   done!\n ");
}

bool   inputpassword()
{
      #define   password_len   6
      char   strpassword[]   =   "123456 ";

      char   ch;
      char   input[_max_path]={0};

      int   nchar=0;
      while(   (ch=_getch())!= '\r ')   {
            putchar( '* ');
            input[nchar]   =   ch;
            ++nchar;          
      }
      if   (nchar!=   password_len)   {
            printf( "\nerror! ");
            exit(1);
      }
      else   {
            if   (strcmp(input,   strpassword)==0)   {
                  printf( "\n ");
                  show();
            }
            else   return   false;
      }

      return   true;
}


int   main()
{
      printf( "please   input: ");
     
      while   (!inputpassword()){
            printf( "\nwrong,   please   input   again: ");
      }

      return   0;
}
发表于:2007-06-10 19:02:054楼 得分:0
#include   <stdio.h>
#include   <stdlib.h>
#include   <string.h>
#include   <conio.h>
void   main()
{
  char   p[30];
  int   i,j;
  char   ch;
  while(1)
  {
    i=0;
   
  while((ch=getch())!= '\r ')
  {
  putchar( '* ');
  p[i]=ch;
          i++;
  }
  p[i]= '\0 ';
  if((strlen(p)==6)&&(!strcmp(p, "123456 ")))
  break;
  else
  printf( "error,input   again!\n ");
          getchar();
  }
  //show();
}
发表于:2007-06-10 20:44:485楼 得分:0
哈哈,牛人很多嘛,都给了。我来接个分
发表于:2007-06-10 21:00:106楼 得分:0
#include   "stdio.h "
#include   "conio.h "
#include   "string.h "

bool   input(char   pass[])
{
        int     cnt   =   0;
        char   t;

        while   ((t   =   getch())   !=   '\r ')
        {
                putch( '* ');
               
                if   (cnt   <=   5)
                        pass[cnt]   =   t;
                cnt++;
        }

        if   (cnt   <   7)
                if   (!strcmp(pass,   "123456 "))
                        return   true;

        return   false;
}

void   show()
{
        printf( "\nyou   are   pass   :)\n\n ");
}

int   main()
{
        char   pass[7]   =   {0};

        while   (!input(pass))
                printf( "\nyou   passworld   error,   please   enter   again   :(   \n\n ");

        show();

        return   0;
}
发表于:2007-06-10 21:24:127楼 得分:0

蹭分专业户松花鼠同学到此一游
发表于:2007-06-11 05:30:198楼 得分:0
en    
本来偶也想写一段
看这么多人抢先了
再写没什么意思了
就不写了

到此一游 留个名
发表于:2007-06-11 07:33:009楼 得分:0
蹭分
发表于:2007-06-11 09:35:1510楼 得分:0
#include   "stdio.h "
#include   "conio.h "
#include   "string.h "

char   buf[10]={0};
void   show(buf[])
{
  return   ((strlen(buf)==6)&&strcmp(buf, "123456 ")==0),0:1;
}

int   main()
{
  printf( "int   put   6   number:\n ");
loop:
  char   c   =   getch();int   i=0;
  while(c!= '\n ')
  {
    buf[i]=c;
    i++;
    c   =   getch();
  }
  if(c   ==   '\n ')
  {
    buf[i]= '\0 ';    
  }
  i=   show(buf[])
  if(i)
  {
    printf( "error,   try   again: ");
    goto   loop;
  }
      return   0;
}
发表于:2007-06-11 20:56:1911楼 得分:0
蹭分是一种好的习惯
发表于:2007-06-15 22:06:3512楼 得分:0
jf
发表于:2007-06-16 11:22:5913楼 得分:0
牛人真的好多
我学习来了
发表于:2007-06-18 17:52:5114楼 得分:0
没想到这么多蹭分同胞!
发表于:2007-06-18 18:28:5715楼 得分:0
mark~
发表于:2007-06-18 19:28:4916楼 得分:0
#include   <stdio.h>
#include   <stdlib.h>
#include   <string.h>
#include   <conio.h>
#define   n   50

void   show()
{
printf( "this   is   the   show\n ");
}
int   main(void)
{
char   pstr[n];
bool   flag=false;
char   ch;
do   {
int   len=0;
printf( "please   input   the   password:\n ");
while((ch=getch())!=13)
{
printf( "%c ", '* ');
pstr[len++]=ch;
}
printf( "\n ");
pstr[len]= '\0 ';
if(len <6)
printf( "the   length   is   too   small,input   again\n ");
else   if(len> 6)
printf( "the   length   is   too   long,input   again\n ");
else
{
if(strcmp(pstr, "123456 ")==0)
flag=true;
else
printf( "password   error,input   again\n ");
}


}   while(!flag);
show();
return   0;
}
发表于:2007-06-19 10:39:3817楼 得分:0
也来接个分


快速检索

最新资讯
热门点击