繁体   English   中英

如何检查两个字符串在C中是否相同?

[英]How can I check if a two strings are the same in C?

我刚刚开始学习C,并且试图习惯语法,因此,当我尝试运行该程序并输入值时,它不会返回任何内容。 我不知道我做错了什么。 谁能帮我吗?

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main()
{
    char pass[10]; //max length of the string;
    do{
        printf("enter your password: \n");
        scanf("%s",pass);
    }while(strcmp(pass,'*') != 0); //checks if strings are equal

    printf("%s",pass);


}

在C语言中,单引号用于字符常量。 因此, '*'不是包含字符*的字符串,而包含字符*

要指定字符串,请使用双引号。

 }while(strcmp(pass,"*") != 0);

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM