#include <windows.h>
#include <stdio.h>
#include <string.h>
#include "stdafx.h"
int main(int argc, char* argv[])
{
char password=0;
printf("Enter the password");
scanf("%d",password);
  if(password=="abc")
  WinExec("cmd.exe", SW_SHOWNORMAL);
  else
  printf("access denied"); return 0;
}
编译报错:
error C2446: '==' : no conversion from 'char *' to 'int'
        This conversion requires a reinterpret_cast, a C-style cast or function-style cast
error C2040: '==' : 'int' differs in levels of indirection from 'char [4]'
执行 cl.exe 时出错.
个人猜测是要进行强制类型转换,不过C当中强制类型转换机制是怎么做的?对VC还不是很熟悉,C也学得不好……Delphi倒是可以Sender as XXXX,C里面该如何去做?

解决方案 »

  1.   

    int main( int argc, char* argv[] )
    {
    char password[128]={0};
    printf( "Enter the password" );
    scanf( "%s", password ); if ( 0 == strcmp( password , "abc") )
    WinExec( "cmd.exe", SW_SHOWNORMAL );
    else
    printf( "access denied" );
    return 0;
    }
      

  2.   


    int main(int argc, char* argv[]) 

      char password[128]={0};//修改 
      printf("Enter the password"); 
      scanf("%s",password); //修改
      if(password=="abc") //两个字符串相比较
      WinExec("cmd.exe", SW_SHOWNORMAL); 
      else 
      printf("access denied"); return 0;