2013-03-19 52 views

回答

1

添加42到原来的STR指针(提防原始字符串长度大于42更大虽然):

first_occurence = strstr(str + 42, substr); 
+0

感谢,是有什么样的的strstr ANSI C的区分大小写的比较? – Sebastian 2013-03-19 15:11:53

+0

@Sebastian:有'strcasestr()'版本,但它是非标准。 – umi 2013-03-19 15:22:55

+0

感谢它的工作!好吧,我现在只有Ü和ü之间的区别和这样的问题。 (它的utf-8编码的C字符串) – Sebastian 2013-03-19 15:29:26

2

只需提供strstr()的指针的第一个字符在SEACH包括:

if(strstr(the_haystack + 42, "the needle") != NULL) 
    printf("found needle at end of haystack!\n"); 

当然,这个假设the_haystack真的是长至少42个字符。