[英]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.