C语言编写一个用户登陆的程序?

Python023

C语言编写一个用户登陆的程序?,第1张

代码如下:

#include<stdio.h>

#pragma warning(disable:4996)

#include<string.h>

int main()

{

int i = 0

char password[10] = { 0 }

printf("请输入密码:")

while (i <3)

{

scanf("%s", password)

printf("\n")

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

{

printf("登录成功\n")

break

}

else

{

i++

if (i != 3)

printf("再输入一次")

}

}

if (i == 3)

printf("密码错误三次退出登录界面\n")

system("pause")

return 0

扩展资料:

#include后面有两种方式,<>;和""前者先在标准库中查找,查找不到在path中查找。后者为文件路径,若直接是文件名则在项目根目录下查找。

引用方法:#include <stdio.h>

注意事项:在TC2.0中,允许不引用此头文件而直接调用其中的函数,但这种做法是不标准的。也不建议这样做。以避免出现在其他IDE中无法编译或执行的问题。

参考资料来源:百度百科—include

参考资料来源:百度百科—stdio.h

#include <stdio.h>

#include <string.h>

#include <stdlib.h>

#include <time.h>

/*随机码产生函数*/

void RandomCode (char Rcode[])

{

int i

srand ((unsigned int)time(NULL))

for (i = 0i <3++i)

Rcode[i] = rand()%10 + '0'

Rcode[i] = '\0'

}

/*登陆函数,判断信息是否匹配,若匹配返回1,否则返回0*/

int LandedApp (char *password[], char Rcode[])

{

char name[10] = {0}

char pword[10] = {0}

char rcode[4] = {0}

printf ("用户名 : ")

gets (name)

printf ("密码 : ")

gets (pword)

printf ("随机码 : ")

gets (rcode)

if (strcmp (name, password[0]) != 0 || strcmp (pword, password[1]) != 0 || strcmp (rcode, Rcode) != 0)

return 0

else

return 1

}

int main ()

{

char * password[2] = {"admin", "admin123"}//用户名和密码

char rc[4] = {0} //随机码

int count = 3 //可输入次数

puts ("请输入用户名,密码和随机码:")

while (count)

{

RandomCode (rc)

printf ("随机码 : %s\n", rc)

if (LandedApp(password, rc) != 0)

break

--count

if (count != 0)

puts ("错误的用户名或密码或随机码,请重新输入: ")

}

if (count != 0)

puts ("\n成功登陆!")

else

puts ("\n登录失败 !")

return 0

}