Re: CODE: Regexp/email check

From: Torgny 'Artovil' Bjers (artovil@unmade.com)
Date: 06/09/01


At 21:39 2001-06-08 -0700, Daniel A. Koepke wrote:
>So the following C code snippet verifies that an e-mail address is of the
>appropriate format and does not have any illegal characters:
>
>   bool valid_email(const char *em) {
>     const char punct_okay[] = "!#$%&'*+/=?^_`{|}~-";
>     char *mailbox;
>     char *domain;
>
>     mailbox = em;
>     domain = strchr(em, '@');
>
>     if (!domain)                /* No '@' separator. */
>       return (FALSE);
>
>     /* Cap mailbox string and make domain point immediately after the @ */
>     *(domain++) = '\0';
>
>     if (!*mailbox || !*domain) /* No mailbox or domain. */
>       return (FALSE);
>
>     while (*mailbox) {
>       if (!isalpha(*mailbox) &&
>           !isdigit(*mailbox) &&
>           !strchr(punct_okay, *mailbox))
>         break;
>
>       mailbox++;
>     }
>
>     while (*domain) {
>       if (!isalpha(*domain) &&
>           !isdigit(*domain) &&
>           !strchr(punct_okay, *domain))
>         break;
>
>       domain++;
>     }
>
>     /*
>      * If we got through entire string without finding a bad character,
>      * then *mailbox == *domain == '\0'.  Otherwise, one or both will
>      * return FALSE as the result of the logical not and the function
>      * returns FALSE to indicate the e-mail address is invalid.
>      */
>     return (!*mailbox && !*domain);
>   }

When I put this in I got a warning for em:

make[1]: Entering directory `/circle/src'
gcc -g -O2 -Wall    -c -o utils.o utils.c
utils.c: In function `valid_email':
utils.c:913: warning: assignment discards qualifiers from pointer target type

What does this mean?  How can I fix it?  I am not a very good C programmer,
but I am learning as I go along.  It would be nice if I had some form of
reference for compiler error messages.  Is there any online sources that I
can turn to, or do I have to buy a book? (My wife will kill me if a buy a C
book for $50 without first buying her every romance novel she missed since
'99. ;])

Kind regards,
Torgny

--
   +---------------------------------------------------------------+
   | FAQ: http://qsilver.queensu.ca/~fletchra/Circle/list-faq.html |
   | Archives: http://post.queensu.ca/listserv/wwwarch/circle.html |
   +---------------------------------------------------------------+



This archive was generated by hypermail 2b30 : 12/05/01 PST