7 c
所以我在一个C代码中得到了这个字符串,我从一本书中有一个引用,然后是另一个字符串,其中有一个单词来自该引用.当它告诉程序找到子串的位置时,它从数字1开始计数而不是0.这是为什么?这就是我的意思:
#include <stdio.h>
#include <string.h>
int main()
{
char str[]="No Time like the Present";
char sub[]="Time";
if (strstr(str, sub)== NULL)
{
printf("not found");
}
else
{
printf("Index number found at %d",strstr(str,sub)-str);
}
return 0
}
Run Code Online (Sandbox Code Playgroud)
所以它会说:索引在3号找到
但是不应该是在2号找到的打印索引,因为你从零开始?或者你有时可以从数字1开始??