C and C++

Moderators: None (Apply to moderate this forum)
Number of threads: 28695
Number of posts: 94715

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
valid email address Posted by bushxee on 18 Mar 2007 at 2:36 AM
This message was edited by bushxee at 2007-3-18 3:3:41

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!!


   #include<stdio.h>
      #include<conio.h>
      #include<string.h>
      void main ()
      {
		clrscr();
		char k[100];
		printf("\n\n\t\tA program to check if an email address is valid or not");
		printf("\n\nEnter any email address:");
		gets(k);
		puts(k);
		if
		(strchr(k,'.') && strchr(k,'@'))
		printf("\n\n\t\tIts a valid email address");
		else
		printf("\n\n\t\tIt is not a valid mail address");
		getch();
      }



Report
Re: valid email address Posted by stober on 18 Mar 2007 at 3:05 AM
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
char iobuf[80];
fgets(iobuf, sizeof(iobuf), stdin);

Report
Re: valid email address Posted by bushxee on 18 Mar 2007 at 3:15 AM
: 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
:
: char iobuf[80];
: fgets(iobuf, sizeof(iobuf), stdin);
: 

:
well thanx but im bound to do it without pointers because my teachers hasnot taught pointers till yet and he told to use gets()
Report
Re: valid email address Posted by subirkumarsao on 18 Mar 2007 at 3:24 AM
: : 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
: :
: : char iobuf[80];
: : fgets(iobuf, sizeof(iobuf), stdin);
: : 

: :
: 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.");

Report
Re: valid email address Posted by stober on 18 Mar 2007 at 12:02 PM
Here is a correction of your program. The original contained a couple bugs.
: 
: char id[30] = {0};
: // take input..
  fgets(id,sizeof(id),stdin);
  // strip training '\n' 
  l=strlen(id);
  if( id[l-1] == '\n')
  {
      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]
Report
Re: valid email address Posted by stober on 18 Mar 2007 at 12:03 PM
: Here is a correction of your program. The original contained a couple bugs.
:
: 
: : int flag1=0,flag2=0;
: : char id[30] = {0};
: : // take input..
:   fgets(id,sizeof(id),stdin);
:   // strip training '\n' 
:   l=strlen(id);
:   if( id[l-1] == '\n')
:   {
:       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]
:

Report
Re: valid email address Posted by stober on 18 Mar 2007 at 6:28 AM
: :
: 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().


Report
Re: valid email address Posted by bushxee on 18 Mar 2007 at 6:46 AM
: : :
: : 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
Report
Re: valid email address Posted by stober on 18 Mar 2007 at 12:04 PM
This message was edited by stober at 2007-3-18 12:5:57

: :
: 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.







 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.