首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C语言 >

初学者的一个程序的有关问题

2012-04-05 
菜鸟的一个程序的问题各位大神,我想问一下这个程序哪里出了问题?# include stdio.h# include string.h

菜鸟的一个程序的问题
各位大神,我想问一下这个程序哪里出了问题?

# include <stdio.h>
# include <string.h>
# define PASSWORD_SIZE 100
# define PASSWODD "myGOODpassword\n"
 main()
{
int count=0,i;
char buff[PASSWORD_SIZE],*a,*b;
a=&buff[0];
b=&PASSWORD;
for(;;)
{
printf("Enter password:");
for(i=0;i<PASSWORD_SIZE;i++)
scanf("%c",&buff[i]);
if(strcmp(a,b))
printf("wrong password\n");
else break;
if(++count>3)
return -1;
}
printf("password ok\n");
}

[解决办法]

C/C++ code
参考下# include <stdio.h># include <string.h>#include<iostream>using namespace std;# define PASSWORD_SIZE 6# define PASSWORD "12345\n"int main(){    int count=0,i;    char buff[PASSWORD_SIZE+1],*a,*b;    a=&buff[0];    b=PASSWORD;    for(;;)    {        printf("Enter password:");        for(i=0;i<PASSWORD_SIZE;i++)            scanf("%c",&buff[i]);        buff[PASSWORD_SIZE] = '\0';        if(strcmp(a,b))            printf("wrong password\n");        else break;        if(++count>3)            return -1;    }    printf("password ok\n");    system("pause");}
[解决办法]
C/C++ code
# include <stdio.h># include <string.h># define PASSWORD_SIZE 100# define PASSWORD "myGOODpassword\n"//PASSWORDvoid main(){    int count=0,i;    char buff[PASSWORD_SIZE],*a,*b;    a=&buff[0];    b=PASSWORD;    for(;;)    {        printf("Enter password:");        for(i=0;i<PASSWORD_SIZE;i++)            scanf("%c",&buff[i]);        if(strcmp(a,b))            printf("wrong password\n");        else break;        if(++count>3)            return -1;    }    printf("password ok\n");} 

热点排行