标题:如何判断输入的一串密码是否与000086相等?
只看楼主
AHAYAOXUEHAO
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2019-3-20
结帖率:0
已结贴  问题点数:20 回复次数:2 
如何判断输入的一串密码是否与000086相等?
    int i,weiqu[1000]={0},j,temp;
     char m;
     printf("请输入万能密码:");
     scanf("%s",&m);
     if (strcmp(m, '000086') == 0)
这个一直显示是编译错误,不知道为什么。
求大佬帮帮忙吧!!!
完整代码如下:
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
void save(int n,int mima,int bianhao);
void get(int n,int *key,int *key1);
void wanneng(int n);
int inputchoice();
int main()
{
    int choice,n,i,key[1000],mima,bianhao,key1[1000];
    printf("寄存箱总数:");
    scanf("%d",&n);
    for(i=0;i<=n;i++)
         {
             key1[i]=key[i]=1000+2*i;
         }
    while((choice=inputchoice())!=0){
              switch(choice){
case 1:
              save(n,mima,bianhao);
              break;
case 2:                     
              get(n,key,key1);
              break;
              default:
                     break;
              }
       }
 }
 int inputchoice()
 {
     int mychoice;
     printf("1.投硬币   2.输密码     0.退出   请选择:");
     scanf("%d",&mychoice);
     return mychoice;
 }
 void save(int n,int mima,int bianhao)
 {
     int i,a,key[1000],key1[1000];
     printf("投币值:");
     scanf("%d",&a);
     if(a==1)
     {
         for(i=0;i<=n;i++)
         {
             key1[i]=key[i]=1000+2*i;
         }
         for(i=0;i<=n;i++)
         {
             if(key1[i]!=0)
             {
                 bianhao=i;
                 mima=key[i];
                 key1[i]=0;
                 break;
             }
             else    continue;
         }
         printf("寄存箱编号:%d   密码:%dn",bianhao,mima);
         if(i>n)    printf("本柜已满n");
     }
 }
 void get(int n,int *key1,int *key)
 {
     int mima,i;
     printf("输入密码:");
     scanf("%d",&mima);
     for(i=0;i<=n;i++)
     {
         if(mima==key[i])
         {
             printf("%d号寄存箱已打开",i);
             key1[i]=key[i];
             break;
         }
     }
 }
 void wanneng(int n,int *key1,int *key)
 {
     int i,weiqu[1000]={0},j,temp;
     char m;
     printf("请输入万能密码:");
     scanf("%s",&m);
     if (strcmp(m, '000086') == 0)

     {
         for(i=0;i<=n;i++)
         {
             if(key1[i]==0)
             {
                 for(j=0;j<=n;j++)
                 {
                     weiqu[j]=i;
                 }
             }
         }
         printf("箱子已经全部打开,请重点检查");
         for(i=0;i<=n;i++)
         {
             if(weiqu[i]!=0)    printf("编号%d",weiqu[i]);
             else    break;
          }
          printf("是否有物留存");
     }
 }
搜索更多相关主题的帖子: 密码 int printf key for 
2019-03-20 17:52
吹水佬
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
等 级:版主
威 望:432
帖 子:10064
专家分:41463
注 册:2014-5-20
得分:10 
if (strcmp(m, '000086') == 0)
字符串用双引号
2019-03-21 04:25
word123
Rank: 10Rank: 10Rank: 10
等 级:贵宾
威 望:13
帖 子:333
专家分:1622
注 册:2014-4-5
得分:10 
char m;    m应该定义为一个字符串
printf("请输入万能密码:");
scanf("%s",&m);
2019-03-22 09:44



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-493707-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.014238 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved