-
input mail
i have function test input mail, but when i have run it, error happen thats Assertion, can you help me, fix it, i dont know fix where.thanks
Code:
//CheckerMail.h"
#include"string"
using namespace std;
class CIMail{
public :
static bool checkpart1(char &chr);
static bool checkpart2(string &str);
static bool checkpart3(string &str);
//static bool checkpart4(string &str);
static int checkchar(string &str);
};
//CheckerMail.cpp"
#include "string"
#include <iostream>
#include "CheckerMail.h"
using namespace std;
bool CheckerMail::checpart1(string &par1){
if(par1.length()==0)return false;
int k=indexdot(par1);
for(int i=k+1;i<sizeof(par1);i++)
if(check(par1[i])){
return true;
}
return false;
}
bool CheckerMail::checper2(string &par2){
if(par2.length()==0)return false;
int h=indexa(par2);
int j=indexdot(par2);
for(int i=h+1;i<j;i++)
if(check(par2[i])||(par2[i]=='.')||(par2[i]=='_')){
return true;
}
return false;
//return true;
}
//
bool CheckerMail::checper3(string &par3){
if(par3.length()==0)return false;
int index=indexa(par3);
for(int i=0;i<index;i++)
if(check(par3[i])||(par3[i]=='%')||(par3[i]=='+')||(par3[i]=='-')||(par3[i]=='.')||(par3[i]=='_')){
return true;
}
return false;
}
//
int CheckerMail::indexa(std::string &str){
for(int i=0;i<sizeof(str);i++){
if(str[i]=='@')return i;
}
return 0;
}
int CheckerMail::indexdot(std::string &str){
int k=0;
for(int i=0;i<sizeof(str);i++){
if(str[i]=='.')
return i;
}
//return k;
return 0;
}
//@
bool CheckerMail::check(char &par){
if((par>='a')&&(par<='z')||((par>='A')&&(par<='Z')))
return true;
return false;
}
//
bool CheckerMail::checmain(std::string &par){
if(!checper2(par)||!checper3(par)||!checpart1(par))return false;
return true;
//return false;
}
///main
#include "string"
#include <iostream>
#include "CheckerMail.h"
using namespace std;
void main(){
string str;
cin>>str;
cout<<CheckerMail::checmain(str);
}
-
- All of your "#include "string""s should be "#include <string>".
- "CheckerMail.h" declares some class "CIMail", but that class is never used. You probably want this class to be called "CheckerMail".
- When you rename the class above, all your signatures will not match any more (not that they do now)--in the header you declare them as static, but in its implementation ("CheckerMail.cpp") they are not static. You probably want them all to be static.
- Also when you rename the above class, the names of the functions dont even match and you dont have them all declared in the header. Your using stuff like "CheckerMail::checmain" and "CheckerMail::indexa" among a number of other functions that arent declared in the header.
- In your header the functions are something with the word "part" in it, but your calling some with "part" and some with "per".
- "void main()" should be "int main(void)", also good idea to add a "return x" at the end of main, for some "int x"
Basically I have no clue what your doing. What compiler are you using and how were you even able to run this?