The strchr () function in C
Char * strchr function (const char * str, int c) looks for the first occurrence of the character c (an unsigned char) in the string pointed to by parameter str.
Char * strchr function (const char * str, int c) looks for the first occurrence of the character c (an unsigned char) in the string pointed to by parameter str.
Declare the strchr () function in C
Below is the declaration for strchr () in C:
char * strchr ( const char * str , int c )
Parameters
str - This is the string to be scanned.
c - This is the character to be searched in str.
Returns the value
This function returns a pointer to the first occurrence of the c character in the str string, or returns NULL if the character is not found.
For example
The following C program illustrates the usage of strchr () in C:
#include #include int main () { const char str [] = "https://QTM.com/lap-trinh-c/index.jsp" ; const char ch = '.' ; char * ret ; ret = strchr ( str , ch ); printf ( "Chuoi dang sau dau |%c| la: n|%s|n" , ch , ret ); return ( 0 ); }
Compiling and running the above C program will result:
According to Tutorialspoint
Previous article: Strncat () function in C
Next article: Function strcmp () in C
You should read it
- The strlen () function in C
- The strerror () function in C
- The strcspn () function in C
- How to 'survive' with the stress of learning programming
- Strncat () function in C
- The strtok () function in C
- The strncpy () function in C
- Bookmark a few tricks to help you master a programming language
- Top 20 free programming learning websites need to bookmark immediately!
- Beginners of computer programming need to focus on what?
- The strspn () function in C
- Set of multiple choice questions about programming with P10 prize
Maybe you are interested
Nvidia just caused the 'blue screen of death' error for Windows Did you know: In addition to the blue screen, does Windows also have a 'dead' green screen? Ways to fix BSOD blue screen error How to find the cause of blue screen death and Minidump errors? How to create a blue screen of death (BSOD) to 'prank' friends Prevent 'blue screen errors' on Windows 8