主要使用的函数:
memchr函数:在某一内存范围中查找一特定字符
#include <string.h>
void *memchr(const void *s,int c,size_t n)
函数说明:函数从头开始搜索s所指的内容内存前N个字节,直到发现第一个值为c的字节,则返回
指向该字节的指针;
返回值:如果找到指定的字节则返回改字节的指针,否则返回0.
判断一个邮箱地址是否合格,检测邮箱地址字符中是否含有@,.,com邮箱地址必须含有的元素,如果不含有则说明邮箱地址不合格。
int judge_email(char *email)
{
int i = 0;
char str;
str = '@';
if(!memchr(email,str,strlen(email)))
{
printf("Mail address is not correct, the lack of @!\n");
return -1;
}
str = '.';
if(!memchr(email,str,strlen(email)))
{
printf("Mail address is not correct, the lack of .!\n");
return -1;
}
if(!strstr(email,"com"))
{
printf("Mail address is not correct, the lack of com!\n");
return -1;
}
return 1;
}