0
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <math.h>
#include <string.h>
int main() {
char userPassword[20];
printf("Type in your password: \n");
scanf("%c", &userPassword);
if (isalpha(userPassword) == 0) {
printf("Nice");
} else {
printf("Nope");
}
return 0;
}
我試圖想出一個代碼在哪裏檢查密碼是否只包含字母。爲什麼此代碼只能使用「== 0」符號。我的朋友告訴我把這個和我的代碼工作。 「== 0」是做什麼的?檢查`isalpha`的返回值
如果你不想'== 0',試着去'如果(因而isalpha(userPassword的)!)' –
你只是閱讀和測試一個字符,而不是一個字符串。 – stark
如果測試失敗,則'isalpha'返回'0'(假),否則如果測試通過則返回非零(真)。所以,使用'!'如上所述。 – Serge