字的字节 returns 比应有的少一

Byte of word returns one less than what it should be

我的教授让我们制作我们自己版本的函数 mystrcat、mystrlen 和 mystrcopy。我有一个问题,这个词 returning 错误的字节数。或者,更确切地说,我认为是。

这句:"HELLO WORLD!",如果我没记错的话,应该是return13个字节吧?喜欢:

const char char_literal[] =
   { 'H', 'E', 'L', 'L', 'O', ' ', 'W', 'O', 'R', 'L', 'D', '!', '[=11=]' };
  //  1    2    3    4    5    6    7    8    9    10   11   12   13 

我把returns({ 'H', 'E', 'L', 'L', 'O', ' '})的函数myStrLen()写成6,但是因为是单独的,所以应该有一个'[=17=]'最后对吗?
那么我应该 returning i + 1 还是 6 正确?

int myStrLen(char stringInput[]){
    for(int i = 0; ; i++){
        if(stringInput[i] == '[=12=]'){
            return i;

如果您的教授告诉您编写一个行为与 strlen 完全相同的函数,那么它不应计算字符串终止字符:

std::size_t strlen( const char* str );

Returns the length of the given byte string, that is, the number of characters in a character array whose first element is pointed to by str up to and not including the first null character. ...

所以返回 i 是正确的,除了 "original" strlen 接受 const 输入参数和 returns size_t...