我刚刚开始学习 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);
}
答案 0 :(得分:4)
在C中,单引号用于字符常量。因此,'*'
不是包含字符*
的字符串,而是仅字符*
。
要指定字符串,请使用双引号。
}while(strcmp(pass,"*") != 0);