让字符串从两边向中间显示
#include<stdio.h>
#include<string.h>
int main()
{
//welcome to xupt!!!!!!
//#####################
//w###################!
//we#################!!
//……
//welcome to xupt!!!!!!
char arr1[] = "welcome to xupt!!!!!!";
char arr2[] = "#####################";
int left = 0;
//int right=sizeof(arr1)/sizeof(arr1[0])-2;
int right = strlen(arr1) - 1;
while (left<=right)
{
arr2[left] = arr1[left];
arr2[right] = arr1[right];
printf("%s\n", arr2);
//休息一秒
Sleep(1000);
system("cls");//执行系统命令的一个函数--cls--清空屏幕
left++;
right--;
}
printf("%s\n", arr2);
return 0;
}
输入三次密码,超过三次退出
#include<stdio.h>
#include<string.h>
#include<windows.h>
#include<stdlib.h>
int main()
{
int i = 0;
char password[20] = { 0 };
for (i = 0; i < 3; i++)
{
printf("input password:");
scanf("%s", password);
if (strcmp(password, "123456") == 0)
{
printf("successful login\n");
break;
}
else
{
printf("input error\n");
}
}
if (i == 3)
{
printf("输入超过三次,请退出\n");
}
return 0;
}