编写代码实现,模拟用户登录场景,并且只能登录三次。

strcmp(str1,str2)

若str1==str2,则返回零;

若str1<str2,则返回负数;

若str1>str2,则返回正数。

int  main()
{
	char psw[20] = { 0 };
	int i = 0;
	for (i = 0; i < 3; i++)
	{
		printf("请输入密码:");
		scanf("%s", psw);
		if (strcmp(psw, "521") == 0)
		{
			printf("密码正确\n");
			break;
		}
		else
		{
			printf("密码错误\n");
		}
	}
	if (i == 3)
		printf("三次都错\n");
	system("pause");
	return 0;
}

猜你喜欢

转载自blog.csdn.net/weixin_41892460/article/details/82811601