這裡蒐索程式師資訊,查找有用的技術資料
当前位置:首页 » 编程语言 » 若姓名正确在输入密码的c语言
扩展阅读
webinf下怎么引入js 2023-08-31 21:54:13
堡垒机怎么打开web 2023-08-31 21:54:11

若姓名正确在输入密码的c语言

发布时间: 2022-04-05 06:31:06

c语言密码输入

简单的

用一个字符数组来存密码

再用一个字符数组接收你的输入,然后用strcmp

来比较,如果返回0则密码是正确的

#include"stdio.h"

#include"string.h"

intmain()

{

charmima[100]="YuanShi888";

charinput[100]={0};

printf("请输入密码:");

gets(input);

if(strcmp(mima,input)==0)

printf("恭喜你,密码正确! ");

else

printf("对不起,密码输入错误! ");

}

② 求一个纯c语言写的口令验证,若密码正确则进入主函数,若密码不正确则推出程序。

#include "stdio.h"
#include "string.h"

void MainProc()
{
}

void main()
{
char pwd[]="123456";
char Ipt[20];
printf("Input password:");
scanf("%s",Ipt);
if(strcmp(pwd,Ipt)!=0)printf(" Password error,Access denied!");
else MainProc();
}

这样可以不,不满意请追问。

③ 进入前输入密码的C语言怎么写

//---------------------------------------------------------------------------

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <conio.h>
#include <ctype.h>

#define PS "abc" /*默认密码*/
#define MPS 3 /*失败重试次数*/

char *getpas(char *s,int n) /*输入密码*/
{
char c;
int i;

memset(s,0,n);
for (i = 0; i<n-1; i++) {
c=getch();
if (isprint(c)) {
s[i]=c=='\r'?'\0':c;
putchar('*');
}
if (c=='\r') break;
}
putchar('\n');
return s;
}
int login(void) /*密码验证函数,如果通过验证则返回1,否则返回0*/
{
char ap[80];
int fg=0;
do
{
puts("密码:");
if (strcmp(getpas(ap,80),PS)&&fg<=MPS) {
printf("输入有误,还有%d次机会\n",MPS-fg);
fg++;
}
else if (strcmp(ap,PS)) puts("密码错误,程序结束!");
else {
puts("密码正确!");
return 1;
}
}while (fg<=MPS);

return 0;
}
int main(void)
{
if (login()) { /*如果密码验证成功,则开始执行程序的主体部分*/
printf("欢迎使用\n");
}
else printf("无此权限\n"); /*如果验证失败,则显示提示信息并退出程序*/
return 0;
}
//---------------------------------------------------------------------------

④ C语言题目 输入密码看是否匹配

姓名部分较简单,你可以自己写。
口令部分写好了。
密码输入:允许回退键更正输入,回车结束输入

#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
main()
{
char p[50];
char UserName[50]="student";
char password[50]="iamtiger";
int i=0;
int n;
printf("Please enter your name:\n");
scanf("%s",UserName);
n=0;
Loop:
i=0;
printf("Please enter your passwd:\n");
fflush(stdin);
while ( i < 50 ){
p[i] = getch();
if (p[i] == '\r') break;
if (p[i] == '\b') { i=i-1; printf("\b \b"); } else {i=i+1;printf("*");};
}
p[i]='\0';
if ( strcmp(password,p)==0) printf("\npasswd is right!\n");
else {
printf("\npassword wrong\n");
n++;
if (n>=3) { printf("Err bye !\n"); return 0;} else goto Loop;
};
return 0;
}

⑤ 用C语言:根据给定的算法,判断输入的密码是否正确

#include<stdio.h>
void main()
{
int n,password=123456,i=1;
while(1)
{
printf("输入密码:");
scanf("%d",&n);
if(n==password)
printf("Welcome to use the software\n");
else
{
if(i<3)
printf("剩余的可输入密码的次数为:%d\n",3-i);
else
printf("Password error ! You can not use the software\n");
i++;

}
if(i>=4||n==password)break;
}
}
这个是不需要用return的,简明一点,初学的应该会

⑥ 在c语言中如何实现1、 编程实现用户登录问题,如果用户名和密码都输入正确,则提示“欢迎登陆!”,假定用

#include<stdio.h>
void main()
{
char name;
int code;
bool b=true;
while(b)
{
printf("\n请输入用户名:");
scanf("%s",&name);
printf("\n请输入密码:");
scanf("%d",&code);
if(name=='h'&&code==0)
{
printf("欢迎光临\n");
b=false;
}
else{
printf("重新登录\n");
}
}
}

希望对你有所帮助,不明白hi我。。

⑦ 用C语言实现让用户输入密码,判断正确否,若正确开始进入下一步新的程序的算法

#include

void
main()
{
int
n,password=123456,i=1;
while(1)
{
printf("输入密码:");
scanf("%d",&n);
if(n==password)
printf("welcome
to
use
the
software\n");
else
{
if(i<3)
printf("剩余的可输入密码的次数为:%d\n",3-i);
else
printf("password
error
!
you
can
not
use
the
software\n");
i++;
}
if(i>=4||n==password)break;
}
}
这个是不需要用return的,简明一点,初学的应该会

⑧ C语言写个程序,已知密码password=123 要求用户输入密码passWord,判断是否正确,输入错误超过3次则退出

#include <stdio.h>

#include <conio.h>

#include <string.h>


int main(void)

{

char password[32];

int i=3;

do{

printf("请输入密码:(还有%d次机会)",i);

scanf("%s",&password);

if(0==strcmp(password,"123"))

{

printf("密码输入正确! ");

break;

}

else

{

printf("密码输入错误,请重新输入! ");

i--;

}

}while(i>0);

getch();

return 0;

}

⑨ 如何设置c语言程序1)管理员先设置用户名和密码,密码以*输出。输入验证,若密码正确,提示进入系统,

#include <stdio.h>
int main()
{
int i=0;
char c;
while(i<20&&(c!='\n'))
{ c=getch();
putchar('*');
++i;
}
getch();
}

⑩ 输入密码正确(三次以内),进入下一指令(c语言程序作答)

#include<stdio.h>

voidabc()
{
printf("correct ");
}
voidmain()
{
intflag=0,i=0,j=0,count=0;
charp[20],c;
charpassword[20]="123456";
for(j=0;j<3;j++)
{
c=0;
count=0;
i=0;
printf("请输入密码 ");
while((c=getchar())!=' ')
{
p[i]=c;
i++;
}
p[i]='';
for(i=0;password[i]!=''||p[i]!='';i++)
{
if(p[i]==password[i])
count++;
}
if(count==i)
{
flag=1;
break;
}
else
{
printf("密码错误 ");
}
}
if(flag)
{
abc();//这里是你密码正确后进入下一个指令的函数
}

}

纯手打和原创,望采纳!