如何在C中高效地计算字符串长度?
我目前使用的方法是:
int calculate_length(char *string) {
int length = 0;
while (string[length] != '\0') {
length++;
}
return length;
}
然而与strlen()相比,它非常慢,有没有其他方法可以做到这一点?
谢谢。
编辑:我正在一个自由环境中工作,不允许使用包括"string.h"在内的任何外部库。