在C语言中,我们可以通过遍历字符串的方式来计算字符串的个数,以下是一个简单的示例:

#include <stdio.h>
#include <string.h>
int main() {
char str[] = "Hello, world!";
int count = 0;
for (int i = 0; str[i] != ' '; i++) {
count++;
}
printf("字符串中的字符个数为: %d
", count);
return 0;
}
在这个示例中,我们首先定义了一个字符串str,然后使用一个for循环遍历这个字符串,当遇到字符串结束符