在C语言里字串不能用 "==" 来直接比较的,要用 strcmp(s1,s2) 这个函数来比较
语法︰int strcmp(char *s1,char *s2)
字串s1 > 字串s2 则传回负值
字串s1 = 字串s2 则传回 0
字串s1 < 字串s2 则传回正值
记得要 #include <string.h> 这个标头档
所以看 strcmp 的传回值是否为 0 就能判断2字串是否相等
判断密码的副程式那边我想应该是要先输入才能去比较巴,所以我把 if() 和 输入 2个顺序反过来。
 i 的范围的话我想应该是从 0~2 ( 0、1、2 )刚好3次,大致上就这些。
复制程式
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
char account[100],result,c[100]="none",y,n;
int i=0,j=0;
char check(char password[100])
{
     for(i=0;i<=2;i++)
     {
         printf("Please input your password:");
         scanf("%s",c);
         if(strcmp(c,password)==0)
            break;
     }
     if(i==3)
        return 'n'
     else
        return 'y'
}
int main(void)
{
    printf("预设帐号:guest 密码:guest\n"); 
    printf("预设帐号:abc   密码:123\n"); 
    printf("预设帐号:qoo   密码:ooo\n"); 
    printf("Please input your account:");
    scanf("%s",account);
    if(strcmp(account,"guest")==0)
    {
       char password[100]="guest";
       result=check(password);
    }
    else 
       if(strcmp(account,"abc")==0)
       {
          char password[100]="123";
          result=check(password);
       }
       else
          if(strcmp(account,"qoo")==0)
          {
            char password[100]="ooo";
            result=check(password);
          }
          else
            result='n'
    if(result=='y')
       printf("输入正确~!!!!\n");
    if(result=='n')
       printf("帐号错误~!!!!\n");
    system("PAUSE");
       
return 0;
}