As IceThatJaw mentioned, it's usually best to give us an indication of what you expect it to output and what it is actually outputting, that makes debugging a lot easier for us.
Now, as for this line:
1 2
//line 37
while (true) //reads until end of file
That's not true - the loop will keep running as long as true == true, meaning forever.
If you want to loop until the end of the file you will need to use some function of the istream that returns a value on which you can base the assumption that there is another line or not.
If you have any further questions, please elaborate a little bit on the problem.
@NwN
I believe the OP is using this line to break out of the infinite loop: if (!fin.good()) break;
This is bad coding, but it should work. I don't understand why they have a while loop set for infinity and then break out that way. I also believe there is an issue with the validation function:
1 2 3 4 5 6
bool validation (char c)
{
bool result = false;
if (c >='A' && c <= 'Z' || c >= 'a' && c <= 'z'|| c >= '0' && c <='9' ||c =='.'||c =='-' || c =='+') result = true;
return result;
}
A few things, you don't need to create a new variable, especially for bool functions. The next issue is that you're not using any parenthesis in your if statement and I don't believe it's handling it like you believe it should. Currently, every condition after the && must be true, and every condition after || can be true. The same code simplified:
1 2 3 4 5
bool validation (char c)
{
if ((c >='A' && c <= 'Z') || (c >= 'a' && c <= 'z')|| (c >= '0' && c <='9') ||c =='.'||c =='-' || c =='+') returntrue;
returnfalse;
}
Even better is to split it up:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
bool validation (char c)
{
// Capital Letters
if (c >='A' && c <= 'Z')
returntrue;
// Lowercase Letters
elseif (c >= 'a' && c <= 'z')
returntrue;
// Numbers
elseif (c >= '0' && c <='9')
returntrue;
// Valid Punctuation
elseif ((c =='.') || (c =='-') || (c =='+'))
returntrue;
returnfalse;
}
for (int i = 0; i > email.length(); i++) That will never run. The loops executes while the condition holds.
As for the reading
1 2
if (!fin.good()) break;
fin >> email; //¿what if it fails here?
Prefer while(fin>>email)
1 2 3 4 5 6 7 8 9 10 11 12
bool validation (char c)
{
// if ((c >='A' && c <= 'Z') || (c >= 'a' && c <= 'z')|| (c >= '0' && c <='9') ||c =='.'||c =='-' || c =='+') return true;
// return false;
return
c >='A' and c <= 'Z' //isupper
or c >= 'a' and c <= 'z' //islower.
//isalpha
or c >= '0' and c <='9' //isdigit
//isalnum
or c =='.' or c =='-' or c =='+';
}
The parenthesis are not needed because of precedence rules