//演示多个字符从两端向中间靠拢
#include<stdio.h>
#include<windows.h>
#include<string.h>
int main()
{
char target[80] = "####################";
char src[] = "welcome to bit-tech!";
int i, j;
printf("%s\n", target);
for (i = 0, j = strlen(src)-1; i <= j; i++, j--)
{
target[i] = src[i];
target[j] = src[j];
Sleep(1000);
printf("%s\n", target);
}
system("pause");
return 0;
}
编码实现,模拟用户登陆情景,并且只允许输入三次密码,如果正确,输出取款,否则退出程序。
//编码实现,模拟用户登陆情景,并且只允许输入三次密码,
//如果正确,输出取款,否则退出程序。
#include<stdio.h>
#include<string.h>
#include<windows.h>
int main()
{
char psw[10] = "";
int i=0;
for (i = 0; i < 3; i++)
{
printf("please input :");
gets_s(psw,10);
if (strcmp(psw, "123456") == 0)
{
break;
}
}
if (i == 3)
{
return 0;
}
else
{
printf("log in\n");
system("pause");
}
return 0;
}