use*_*055 -1 c c-strings counting char
我只需要计算字符串中的句点 (.)。为此,我使用库ispunct中的函数ctype.h。我不想计算逗号 (,),也不想计算感叹号 (!)。
ispunct
ctype.h
我怎样才能只计算一个周期?
当我使用ispunctctype 库中的函数时,我的程序会计算句点 (.)、逗号 (,) 和感叹号。
Chr*_*ris 5
如果ispunct它不能满足您的需要,请不要使用它。只需检查与 是否相等'.'。
'.'
size_t count_periods(const char *s) { size_t count = 0; for (size_t i = 0; s[i]; i++) { if (s[i] == '.') count++; } return count; }
归档时间:
2 年,1 月 前
查看次数:
161 次
最近记录: