用c語言判斷email地址下面4點,出現一種就報error
1.email地址中第一位是@符號
2.email地址中最后一位是@符號
3.email地址中沒有出現@符號
4.email地址中出現2次以上@符號
uj5u.com熱心網友回復:
#include <stdio.h>
#include <string.h>
int check_at_ch(char *src);
int main()
{
char str[] = "xx@xxxx";
if (check_at_ch(str) < 0)
printf("error!\n");
printf("%d\n", check_at_ch(str));
return 0;
}
int check_at_ch(char *src)
{
char *pstr;
unsigned int pos;
pstr = strchr(src, '@');
if (!pstr) //no '@'
return -3;
pos = pstr - src;
if (pos == 0) //at first
return -1;
else if (pos == strlen(src) - 1) //at end
return -2;
else if (strchr(pstr+1, '@')) //appear more than 2 times
return -4;
else
return 0;
}
供參考~
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/283858.html
標籤:C語言
上一篇:谷歌C++編程規范,高(zhuang)端(bi)程式員必看檔案
下一篇:請問如何分配安排一個大的程式
