要求:用栈来做一个密码验证程序,密码验证只有三次机会
请问我下面程序中哪里出现了错误?
#include<stdio.h>
#include<string.h>
#include<conio.h>
#include<stdlib.h>
#define STACK_INIT_SIZE 10
#define OK 1
#define TRUE 1
#define FALSE  0
#define ERROR 0
char PASSWORD="abcdef"; /*密码,全局变量*/
typedef char SElemType;
typedef struct STACK /*定义栈类型*/
{
  SElemType *base;
  SElemType *top;
  int stacksize;
  int length;
}SqStack,*Stack;
typedef int Status;
void InitStack(Stack *S) /*初始化栈*/
{
  *S=(SqStack *)malloc(sizeof(SqStack));
  (*S)->base=(SElemType *)malloc(STACK_INIT_SIZE*sizeof(SElemType));
  if(!(*S)->base)exit(-1);
  (*S)->top=(*S)->base;
  (*S)->stacksize=STACK_INIT_SIZE;
  (*S)->length=0;
}
Status DestroyStack(Stack *S) /* 销毁栈*/
{
 free((*S)->base);
 free((*S));
 return OK;
}
void ClearStack(Stack *S)  /*把栈置为空*/
{
  (*S)->top=(*S)->base;
  (*S)->length=0;
}
Status StackEmpty(SqStack S) /*判断栈空否*/
{
  if(S.top==S.base) return TRUE;
  else
    return FALSE;
}
void Push(Stack *S,SElemType e)  /*把数据压入栈*/
{
  if((*S)->top - (*S)->base>=(*S)->stacksize)
   {
     (*S)->base=(SElemType *) realloc((*S)->base,
     ((*S)->stacksize + 2) * sizeof(SElemType));
     if(!(*S)->base)exit(-1);
     (*S)->top=(*S)->base+(*S)->stacksize;
     (*S)->stacksize += 2;
   }
  *((*S)->top++)=e;
  ++(*S)->length;
}
Status Pop(Stack *S) /*删除栈顶元素*/
{
  if((*S)->top==(*S)->base) return ERROR;
  (*S)->top--;
  --(*S)->length;
  return OK;
}
Status GetTop(Stack S,SElemType *e)/*返回栈顶元素*/
{
  if(S->top==S->base) return ERROR;
  *e=*(S->top-1);
  S->top--;
}
void Change(SqStack S,char *a) /*将栈中的元素按反序付给 a */
{ int n=S.length-1 ;
  while (!StackEmpty(S))
      GetTop(&S,&a[n--]);
}
void Control(Stack *s)
{int i=0,k,j=0;
 SElemType ch,*a;
 k=strlen(PASSWORD);
 printf("输入一个 %d 个数的密码,你只有 3 次机会:\n",k);
 printf("C:\\>");
 for(;;)
  { if(i>=3)
 {  i++;
    clrscr();
    gotoxy(1,1); /*定位黑屏光标位置*/
    break;
  }
     else if(i>0&&i<3)
 {  gotoxy(5,2);
    for(j=1;j<=(*s)->length;j++)printf(" ");
    gotoxy(5,2);ClearStack(s);}
     for(;;)  /* 密码输入,可退格 */
 {ch=getch();  /* 退格 的ASCII 是8 */
  if(ch!=13) /* 判断是否为回车,不是则把它付给下面*/
     {if(ch==8) {Pop(s);gotoxy(4+j,2);printf(" ");gotoxy(4+j,2);}
      else {printf("*");Push(s,ch);}
      j=(*s)->length;}
  else break;
 }
      i++;
     if(k!=j) continue; 
     else  
       { a=(SElemType *)malloc((*s)->length*sizeof(SElemType));
  Change(**s,a);
  for(j=1;j<=(*s)->length;)
     {if(a[j-1]==PASSWORD[j-1]) j++;
      else {j=(*s)->length+2;break;}}
     if(j==(*s)->length+2) continue;
     else break;}}/*最上面的for完*/
 if(i==4) printf("\n密码错误,即将退出");
 else printf("\n密码正确\n");
 free(a);
}
main()
{Stack s;
 clrscr();/*清屏*/
 InitStack(&s);
 Control(&s);
 getch();
 DestroyStack(&s);
} 编译后出现的错误提示:
--------------------Configuration: 123 - Win32 Debug--------------------
Compiling...
123.cpp
C:\Documents and Settings\zhangjie.WWW-68878C32228\桌面\123.cpp(10) : error C2440: 'initializing' : cannot convert from 'char [7]' to 'char'
        This conversion requires a reinterpret_cast, a C-style cast or function-style cast
C:\Documents and Settings\zhangjie.WWW-68878C32228\桌面\123.cpp(80) : error C2664: 'strlen' : cannot convert parameter 1 from 'char' to 'const char *'
        Conversion from integral type to pointer type requires reinterpret_cast, C-style cast or function-style cast
C:\Documents and Settings\zhangjie.WWW-68878C32228\桌面\123.cpp(86) : error C2065: 'clrscr' : undeclared identifier
C:\Documents and Settings\zhangjie.WWW-68878C32228\桌面\123.cpp(87) : error C2065: 'gotoxy' : undeclared identifier
C:\Documents and Settings\zhangjie.WWW-68878C32228\桌面\123.cpp(108) : error C2109: subscript requires array or pointer type
C:\Documents and Settings\zhangjie.WWW-68878C32228\桌面\123.cpp(123) : warning C4508: 'main' : function should return a value; 'void' return type assumed
执行 cl.exe 时出错.123.obj - 1 error(s), 0 warning(s)请问高手到底哪里错误了 请指点下  谢谢!!

解决方案 »

  1.   

    就是全局变量的定义有点错误,改成这样就可以正常运行了。 
    char PASSWORD[]="abcdef"; /*密码,全局变量*/ 
      

  2.   

    应该添加类库,你没有添加,你没主意到有些函数,没有定义吗?如:gotoxy
      

  3.   

    除了char PASSWORD[]="abcdef"; /*密码,全局变量*/ ,应该添加类库,你没有添加,你没主意到有些函数,没有定义吗?如:gotoxy()
      

  4.   

    除了char PASSWORD[]="abcdef"; /*密码,全局变量*/ ,应该添加类库,你没有添加,你没主意到有些函数,没有定义吗?如:gotoxy()