Hi,
there is a function "strchr()".
It returns a pointer to the first occurance of given character in string (if there isn't, it returns "NULL").
But what happen if I will call this function TWICE or MORE?
For example, we have a program:
I found out that at FIRST call this function returns to me a pointer to the FIRST occurance of 'P', and at SECOND call it returns to me a pointer to the SECOND occurance of 'P'.Code:#include <stdio.h> #include <string.h> int main(void) { char str[] = "APPLE"; /* A whatever string */ strchr(str, 'P'); /* First call of function */ strchr(str, 'P'); /* Second call of function */ return 0; }
Everywhere is written about this function that it returns a first occurance, but nowhere is written what will happen if I call this function twice or more.
So if anybody can tell me, what will happen at the second call, if it skip the previous found one and if yes, how does the function know which was the last found character, if it save the last pointer to some "his" memory or what?
And if it is so, that I have described it above, what would happen if I changed after the first call the value of "str" to the new value:
so if after that change, the SECOND call of the function returns a pointer to 'P' (the first character of "PEACH"), or if it retuns "NULL" (because the first call returned the second letter of "APPLE" and in "PEACH", the 'P' is the first letter, so if it goes back to the beginning of the word or NEVER)?Code:str == "PEACH"
Thanks for answers.
Petike.