When I was writing a program, I suddenly needed to locate a character in a string for the first time. So I found the strchr () function, which was never used before, ^ _ ^ of course, I can call it directly, but the laundry bag with good programming quality decides that it is not that difficult to implement this function. Loop traversal, until the first occurrence of the character you need to find ends. Hey, record it a little for future use.
Therefore, with a learning attitude, the following code emerged:
Char * mystrchr (const char * s, int C)// Return the address of the character you are looking
{
For (; * s! = (Char) C; ++ S)
{
If (* s = '\ 0 ')// The description is complete.
Return NULL;// If no result is found, the system returns NULL.
}
Return (char *) S;// Address of the character we need
}
We can define a string first.Then, we can use our own mystrchr () function,
For example, search for 'G ':
Puts (mystrchr (string address, 'G'); because it is defined in the int type, our characters are searched in the form of aiiss, the output is the string starting with the first G.