试对图3-23所示的“Emai地址验证”程序儆出修改,
新的合法性验证要求,在E-mail地址宇符串中,
符号@前、符号@和.之间、符号.之后,至少存在一个字母。
满足这种要求的Emal地址,才认为是合法的。
#include <stdio.h>
#define FAlSE 0
#define TRUE 1
int main()
{
char nextChar;
char nowChar = ' ';
int gotAt;
int gotDot;
int gotLetter;
printf("Enter your e-mail address: ");
do
{
scanf("%c", &nextChar);
if (nextChar == '@')
{
if (nowChar != ' ')
{
nowChar = '@';
gotAt = TRUE;
}
else
break;
}
else if (nextChar == '.' && gotAt == TRUE)
{
if (nowChar != '@')
{
nowChar = '.';
gotDot = TRUE;
}
else
break;
}
else if (nowChar == '.' && (nextChar == '\n' || nextChar == ' '))
break;
nowChar = nextChar;
} while (nextChar != ' ' && nextChar != '\n');
if (gotAt == TRUE && gotDot == TRUE && nowChar != '.')
printf("Your e-mail address appears to be valid.\n");
else
printf("Your e-mail address is not valid!\n");
}