I am stuck on this part

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#include <iostream>
#include <fstream>
#include <iomanip> 
#include <string>
using namespace std;
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;
}

int main () {
    
	//bool ValidEmailCharacters;
	string lineFromFile;
    int locationOfAtSign = -1;
    int beforeatsign;
	int afteratsign;
	
	string InputfileName; 
	string OutputFileName;
	string defaultInputFile = "fileContainingEmails.txt";
	string defaultOutputFile = "copyPasteMyEmail.txt"; 
	
	ifstream fin;
	ofstream fout;
	
	cout << "Enter your Input file name  (ENTER for Default): " ;
	getline (cin, InputfileName);
	if (InputfileName.length() < 2) {
	    InputfileName = defaultInputFile;
	}
    fin.open (InputfileName);
	
	cout << "Enter your Output file name (ENTER for Default): " ;
	    getline (cin, OutputFileName);
	if (OutputFileName.length() < 2) {
	    OutputFileName = defaultOutputFile;
	}
	fout.open (OutputFileName);
	
	// Read a line from the input file
	while (!fin.eof())    //reads until end of file
	{
	    // 
		fin >> lineFromFile;
		
		if (!fin.good()) break;
		
		cout << lineFromFile <<		"////////////////////////////////////////////////////////////////////////// "<< endl;
		
		// process the line
		for (int i = 0; i < lineFromFile.length(); i++) 
		{
			if (lineFromFile[i] == '@') 
			{
				locationOfAtSign = i; 
				cout << "Test1-Found at sign" << endl;
			}
		}
				//checking at left of at sign
				for(beforeatsign = locationOfAtSign-1; beforeatsign  >= 0; beforeatsign--) 
				{   
				    if (lineFromFile[beforeatsign] == 'x') break;
					cout << "Test2- check to left of the at sign" << endl;
					if (validation(lineFromFile[beforeatsign]) == false) break;
				}
					
					    cout << "validating" << endl;
			      		// checking to the right of the at sign
				for (afteratsign = locationOfAtSign+1; afteratsign < lineFromFile.length();   afteratsign++)      
						{
						    if (lineFromFile[afteratsign] == 'x') break;
						    cout << "check to right of the at sign" << endl;
					        bool Dot = false;
							if (validation(lineFromFile[afteratsign]) == false) break;
							if (lineFromFile[afteratsign] == '.') Dot = true;
							//fout << lineFromFile << ";" << endl;
							
						}
			//	if (lineFromFile[beforeatsign] == 'x' && lineFromFile[afteratsign] == 'x') break;
				
			    if ((beforeatsign != 'x' && afteratsign != 'x') == true)break;
				{
				fout << lineFromFile << ";" << endl;
                }
		
	

		}

	
	
	fin.close();

	return 0 ;
	
}
		


on line 85 i didnt do that part right i need help on correcting it so that it checks if the email is valid or not. If it is valid it fouts it if its not it skips that email and goes on to the next.
I think you need to get rid of break; from line 85, or perhaps move it into a new 'else' block.
Last edited on
i tried using else but it said that i didnt use it correctly
1
2
C:\Users\Patrick Nguyen\Desktop\testingfile.cpp(89) : error C2181: illegal else
without matching if


1
2
3
4
5
			    if ((beforeatsign != 'x' && afteratsign != 'x') == true);
				{
				fout << lineFromFile << ";" << endl;
                }
				else break;
close - at the end of the if statement, you have a ";" - remove that and you should be good.
it is still not testing correctly.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#include <iostream>
#include <fstream>
#include <iomanip> 
#include <string>
using namespace std;
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;
}

int main () {
    
	//bool ValidEmailCharacters;
	string lineFromFile;
    int locationOfAtSign = -1;
    int beforeatsign;
	int afteratsign;
	
	string InputfileName; 
	string OutputFileName;
	string defaultInputFile = "fileContainingEmails.txt";
	string defaultOutputFile = "copyPasteMyEmail.txt"; 
	
	ifstream fin;
	ofstream fout;
	
	cout << "Enter your Input file name  (ENTER for Default): " ;
	getline (cin, InputfileName);
	if (InputfileName.length() < 2) {
	    InputfileName = defaultInputFile;
	}
    fin.open (InputfileName);
	
	cout << "Enter your Output file name (ENTER for Default): " ;
	    getline (cin, OutputFileName);
	if (OutputFileName.length() < 2) {
	    OutputFileName = defaultOutputFile;
	}
	fout.open (OutputFileName);
	
	// Read a line from the input file
	while (!fin.eof())    //reads until end of file
	{
	    // 
		fin >> lineFromFile;
		
		if (!fin.good()) break;
		
		cout << lineFromFile <<		"////////////////////////////////////////////////////////////////////////// "<< endl;
		
		// process the line
		for (int i = 0; i < lineFromFile.length(); i++) 
		{
			if (lineFromFile[i] == '@') 
			{
				locationOfAtSign = i; 
				cout << "Test1-Found at sign" << endl;
			}
		}
				//checking at left of at sign
				for(beforeatsign = locationOfAtSign-1; beforeatsign  >= 0; beforeatsign--) 
				{   
				    if (lineFromFile[beforeatsign] == 'x') break;
					cout << "Test2- check to left of the at sign" << endl;
					if (validation(lineFromFile[beforeatsign]) == false) break;
				}
					
					    cout << "validating" << endl;
			      		// checking to the right of the at sign
				for (afteratsign = locationOfAtSign+1; afteratsign < lineFromFile.length();   afteratsign++)      
						{
						    if (lineFromFile[afteratsign] == 'x') break;
						    cout << "check to right of the at sign" << endl;
					        bool Dot = false;
							if (validation(lineFromFile[afteratsign]) == false) break;
							if (lineFromFile[afteratsign] == '.') Dot = true;
							//fout << lineFromFile << ";" << endl;
							
						}
			//	if (lineFromFile[beforeatsign] == 'x' && lineFromFile[afteratsign] == 'x') break;
				
			    if ((beforeatsign != 'x' && afteratsign != 'x') == true)
				{
				fout << lineFromFile << ";" << endl;
                }
				else break;
		
	

		}

	
	
	fin.close();

	return 0 ;
	
}
		



input file
1
2
3
4
5
6
7
8
9
10
11
file@gmail.com     trdy@tester.com
pcnjijjijij@gmail.com
hi122344@yahoo.com
rain@wall.com
@@@@cjdk;lafjdsf
igloo@sas.com

fasfasdf@@fadjklf.gmail.com

elmoa@gmail.com     igloo@gmail.com
out put
1
2
3
4
5
6
7
8
9
10
file@gmail.com;
trdy@tester.com;
pcnjijjijij@gmail.com;
hi122344@yahoo.com;
rain@wall.com;
@@@@cjdk;lafjdsf;
igloo@sas.com;
fasfasdf@@fadjklf.gmail.com;
elmoa@gmail.com;
igloo@gmail.com;
my arguments are still wrong could you help me find the correct things to put in it?
Topic archived. No new replies allowed.