valid email address - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

valid email address

bushxeebushxee Posts: 16Member
[b][red]This message was edited by bushxee at 2007-3-18 3:3:41[/red][/b][hr]
Im making a program that checks whether the entered email address is valid or not.. the coding that ive done doesnot checks the company and domain plss can any one help out what to add in it.. P.S IvE not studied pointers yet.. cheers!!


[code] #include
#include
#include
void main ()
{
clrscr();
char k[100];
printf("

A program to check if an email address is valid or not");
printf("

Enter any email address:");
gets(k);
puts(k);
if
(strchr(k,'.') && strchr(k,'@'))
printf("

Its a valid email address");
else
printf("

It is not a valid mail address");
getch();
}
[/code]


Comments

  • stoberstober Posts: 9,765Member ✭✭✭
    About all your program can check is the presence of '@' and spaces. Otherwise the only way I know of to validate an email address is to send an email to it and get a reply.

    And you better study pointers before you do that or else you will be completly lost and over your head.

    Also, never use gets() because it causes too many problems. use fgets() instead, like this example
    [code]
    char iobuf[80];
    fgets(iobuf, sizeof(iobuf), stdin);
    [/code]
  • bushxeebushxee Posts: 16Member
    : About all your program can check is the presence of '@' and spaces. Otherwise the only way I know of to validate an email address is to send an email to it and get a reply.
    :
    : And you better study pointers before you do that or else you will be completly lost and over your head.
    :
    : Also, never use gets() because it causes too many problems. use fgets() instead, like this example
    : [code]
    : char iobuf[80];
    : fgets(iobuf, sizeof(iobuf), stdin);
    : [/code]
    :
    well thanx but im bound to do it without pointers because my teachers hasnot taught pointers till yet and he told to use gets()
  • subirkumarsaosubirkumarsao Posts: 5Member
    : : About all your program can check is the presence of '@' and spaces. Otherwise the only way I know of to validate an email address is to send an email to it and get a reply.
    : :
    : : And you better study pointers before you do that or else you will be completly lost and over your head.
    : :
    : : Also, never use gets() because it causes too many problems. use fgets() instead, like this example
    : : [code]
    : : char iobuf[80];
    : : fgets(iobuf, sizeof(iobuf), stdin);
    : : [/code]
    : :
    : well thanx but im bound to do it without pointers because my teachers hasnot taught pointers till yet and he told to use gets()
    :

    can we do this way?

    char id[30];
    l=strlen(id);

    // take input..

    int flag1=0,flag2=0;

    for(int i=0;i<l;i++)
    {
    if(id[i]=='@')
    flag1=0;
    if(id[i]=='.')
    flag2=0;
    }
    if(flag1&&flag2)
    printf("Valid");
    else
    printf("Invalid.");

  • stoberstober Posts: 9,765Member ✭✭✭
    : :
    : well thanx but im bound to do it without pointers because my teachers hasnot taught pointers till yet and he told to use gets()
    :

    Oh I see now. I didn't realize you were a student. And you can tell your teacher for me that he/she is an idot for telling students to use gets().


  • bushxeebushxee Posts: 16Member
    : : :
    : : well thanx but im bound to do it without pointers because my teachers hasnot taught pointers till yet and he told to use gets()
    : :
    :
    : Oh I see now. I didn't realize you were a student. And you can tell your teacher for me that he/she is an idot for telling students to use gets().
    :
    :
    :
    welll he is my teacher i cant say anything to him... but subir the prg u gave is giving invalid for every email address even if it is valid...:S
  • stoberstober Posts: 9,765Member ✭✭✭
    Here is a correction of your program. The original contained a couple bugs.
    [code]:
    : char id[30] = {0};
    : // take input..
    fgets(id,sizeof(id),stdin);
    // strip training '
    '
    l=strlen(id);
    if( id[l-1] == '
    ')
    {
    id[l-1] = 0;
    --l;
    }
    :
    : int flag1=0,flag2=0;
    :
    : for(int i=0;i<l;i++)
    : {
    : if(id[i]=='@')
    : flag1=1;
    : if(id[i]=='.')
    : flag2=1;
    : }
    : if(flag1&&flag2)
    : printf("Valid");
    : else
    : printf("Invalid.");
    :
    :
    [/code]
    [/code]
  • stoberstober Posts: 9,765Member ✭✭✭
    : Here is a correction of your program. The original contained a couple bugs.
    : [code]:
    : : int flag1=0,flag2=0;
    : : char id[30] = {0};
    : : // take input..
    : fgets(id,sizeof(id),stdin);
    : // strip training '
    '
    : l=strlen(id);
    : if( id[l-1] == '
    ')
    : {
    : id[l-1] = 0;
    : --l;
    : }
    : :
    : :
    : : for(int i=0;i<l;i++)
    : : {
    : : if(id[i]=='@')
    : : flag1=1;
    : : if(id[i]=='.')
    : : flag2=1;
    : : }
    : : if(flag1&&flag2)
    : : printf("Valid");
    : : else
    : : printf("Invalid.");
    : :
    : :
    : [/code]
    : [/code]
    :

  • stoberstober Posts: 9,765Member ✭✭✭
    [b][red]This message was edited by stober at 2007-3-18 12:5:57[/red][/b][hr]
    : :
    : welll he is my teacher i cant say anything to him...

    Yes, I know -- but wouldn't you just love to tell stupid teachers off like that ? YOU can't, but I can :-)

    And see my correction of subir's code. It had a couple bugs.




Sign In or Register to comment.