#include
using namespace std;
int main() {
cout<<"Please enter a sentence in English."<
char sentence[500];
cin.getline (sentence,500);
int count = 0;
int i;
for(char *str = sentence ; str[i] ; str++) {
if((str[i] >= 'a' && str[i] <= 'z')||(str[i] >= 'A' && str[i] <= 'z')) {
count++;
}
}
cout<<"There are "<<count<<" letters in this sentence."<<endl;
return 0;
}
代碼如上,請問大神for循環中的條件是什麼意思呢?求講的詳細一些...
測試條件是數組當前值非空就繼續走,如果這個字符落在大小寫a到z或者是0-9則計數器加1,不過,你頭文件沒包含iostream ,i也沒初始化,編譯即報錯。