以下是引用m456m654在2009-10-9 16:46:48的发言:
/* Note:Your choice is C IDE */
#include "stdio.h"
void main()
{
char s[10],s1[]="12345";
int i;
for(i=0;i<3;)
{
printf("please input the possword:\n");
gets(s ...
修改一下,这样会更好:
/* Note:Your choice is C IDE */
#include <stdio.h>
#include <string.h>
#define PASSWORD "12345"
int main()
{
char s[6];
int i = 0;
printf("please input the password:\n");
do
{
i++;
fgets(s,6,stdin);
if(!strcmp(s,PASSWORD))
{
printf("Welcome.\n");
system("PAUSE");
return 0;
}
else
{
if(i < 3)
printf("please try again:\n");
}
fflush(stdin);
}while(i < 3);
printf("Sorry!\n");
system("PAUSE");
return 1;
}
不然gets的bug会导致输入一次就死了,比如长度超过18个字符。