[英]How can I check if a two strings are the same in C?
I've just started learning C and I'm trying to get used to the syntax, so when I try to run the program and enter the value it doesn't return anything. 我刚刚开始学习C,并且试图习惯语法,因此,当我尝试运行该程序并输入值时,它不会返回任何内容。 I don't know what I did wrong.
我不知道我做错了什么。 Can anyone help me please?
谁能帮我吗?
#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);
}
In C, single quotes are used for character constants. 在C语言中,单引号用于字符常量。 So
'*'
is not a string containing the character *
but only the character *
. 因此,
'*'
不是包含字符*
的字符串,而仅包含字符*
。
To specify a string, use double quotes. 要指定字符串,请使用双引号。
}while(strcmp(pass,"*") != 0);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.