While writing a function to count in how many individual position the string sub appears in the string s i found that the for-loop didn't work when using the empty string as s.
char* s = "";
char* sub = "up";
for(int i = 0; i <= (strlen(s) - strlen(sub)); i++){
//stuff
}
In this case the loop kept going as if the condition wasn't met.
However if i rewrite the condition this way it works as intended.
int max = strlen(s) - strlen(sub);
for(int i = 0; i <= max; i++){
//stuff
}
So i was wondering what is it that could cause this kind of behaviour.