我正在尝试编写一个小程序,我基本上计算函数中的字符串长度,但由于某种原因它没有向命令行输出任何内容。
#include <stdio.h>
int search (char* string, char* substring){
int length = 0;
while(substring){
substring++;
length++;
}
return length;
}
int main(int argc, const char * argv[])
{
char string1[] = "hello world";
char* string = string1;
char substring1[] = "world";
char* substring = substring1;
int a = search(string,substring);
printf("%d", a);
return 0;
}