User Tools

Site Tools


Sidebar

Programming Reference/Librarys

Question & Answer

Q&A is closed







c:string.h:memchr
    void *memchr(const void *str, int c, size_t n);

memchr finds the firs occurrence of a character and return a pointer to it.

#include <stdio.h> /* including standard library */
//#include <windows.h> /* uncomment this for Windows */
 
#include <string.h>
 
int main( void ) {
 
char string[] = "Find the firs occurrence of a character and count it !";
if( memchr(string,'o',strlen(string)) == NULL ) {
     printf( "Cant find o character\n" ); 
   }
    else {
      printf( "found character o at position %li\n", (char *)memchr(string,'o', strlen(string))-string+1 );
      }
 
return 0;
}
  output:
  user@host:~$ ./memchr 
  found character o at position 15

on the occasion of the current invasion of Russia in Ukraine

Russian Stop this War
c/string.h/memchr.txt · Last modified: 2024/02/16 01:06 (external edit)

Impressum Datenschutz