User Tools

Site Tools


Sidebar

Programming Reference/Librarys

Question & Answer

Q&A is closed







c:string.h:strcspn

strcspn

#include <string.h>
//#include <windows.h> /* uncomment this for Windows */
 
    size_t strcspn(const char *str1, const char *str2);

Description

strcspn find the first occurrence of any character in str2

strcspn C Example Code

/* 
 * strcspn c example code
 * http://code-reference.com/c/string.h/strcspn 
 */
#include <stdio.h>
#include <string.h>
#include <stdlib.h> /* for strlen */
int main ( void )
{
  char string[] = "te=st@code-reference.com";
  char search_keys[] = "?! ,$%:;&/()=";
  size_t found;
 
  found = strcspn(string,search_keys);
 
  if (found > 0 && found < strlen(string)) {
          printf("is not a e-mail address found incorrect char at position: %i\n",  found );
     }
      else {
         printf("valid e-mail :)\n");
       }
  return 0;
}

Output of strcspn example

  user@host:~$ ./strcspn 
  is not a e-mail address found incorrect char at position: 2

on the occasion of the current invasion of Russia in Ukraine

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

Impressum Datenschutz