User Tools

Site Tools


Sidebar

Programming Reference/Librarys

Question & Answer

Q&A is closed







c:string.h:strchr

strchr

    char *strchr(const char *str, int c);

strchr finds the first occurrence of a character and return a pointer to it.

C Sourcecode Example

/* 
 * strchr c example code
 * http://code-reference.com/c/string.h/strchr 
 */
#include <stdio.h> /* including standard library */
//#include <windows.h> /* uncomment this for Windows */
 
#include <string.h>
 
int main( void ) {
char *ptr;
char string[] = "Find the first occurrence of a character and count it !";
if( strchr(string,'o') == NULL )
  printf( "Cant find o character\n" );
else {
     ptr=strchr(string,'o');
     printf( "found character o at position %i\n", ptr-string+1 );
  }
return 0;
}

strchr Output for this example

  user@host:~$ ./strchr 
  found character o at position 15
advertising
c/string.h/strchr.txt · Last modified: 2015/01/10 19:10 by 2001:a60:240a:7001:896a:d8c6:fabb:d134

Impressum Datenschutz