So, I have this line in C code, which I got from a book that has a quote, and then another line that has one word from this quote. When he tells the program to find the position of the substring, it starts the count from number 1, not 0. Why is this? Here is what I mean:
#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 }
So this will say: Index found at number 3
But shouldn't you print the index found at number 2 because you are starting from scratch? Or you can sometimes start with number 1 ??!
c
user1800989
source share