Skip to main content

  | मौसम…

411 समाचार
Public archive edition · Attributed source reporting with original dates · AI drafts are excluded

411 REFERENCE · Wikibooks

C programming/string.h/strrchr

Reference material by Wikibooks contributors. This retains its source identity and is not 411 news reporting.

strrchr is function in string.h.http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1124.pdf ISO/IEC 9899:1999 specification p. 343, § 7.12.4.3 It is mainly used to locate last occurrence of character in string, searching from the end. It returns a pointer to the last occurrence of character in the C string str. The terminating null-character is considered part of the C string. Therefore, it can also be located to retrieve a pointer to the end of a string. Syntax In C, this function is declared as: char *strrchr ( const char *, int ); str is a C string. character is the character to be located. It is passed as its int promotion, but it is internally converted back to char. Return value A pointer to the last occurrence of character in str. If the value is not found, the function returns a null pointer. Example #include <stdio.h> #include <string.h> int main(void) { const char *str = "This is a sample string"; char *pch = strrchr(str, 's'); printf("Last occurrence of 's' found at %d\n", pch - str + 1); return 0; } Output : Last occurrence of 's' found at 18. See also strchr References External links some information about strchrnul C++ reference for std::strrchr deep