Programming Reference/Librarys
Question & Answer
Q&A is closed
#include <string.h> //#include <windows.h> /* uncomment this for Windows */ size_t strcspn(const char *str1, const char *str2);
strcspn find the first occurrence of any character in str2
/* * 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; }
user@host:~$ ./strcspn
is not a e-mail address found incorrect char at position: 2