using to lower to output edited html tags into new file

Hi making a program to detect html tags ( as well as other things) and then convert any tags that contain an upper-case character, to lower-case, then outputting it to a second specified file without altering the original file. Could someone give me an idea of how to do this? My program is miscalculating the amount of tags in the file, so if someone could also give me some tips for getting that to work correctly; I'd appreciate it. My code is below

Thanks.
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
103
104
105
106
107
108
109

// assignment program 
// read file and copy to another
// count amount of charecters,lines, comments and tags
// change Xhtml tags from upper case to lower case
// place in new file 

#include <iostream>
#include <fstream>
#include <string>
#include <cstring>
#include <iomanip> 
#include <cstype>
using namespace std;

int main()
{
string file1,file2;
ifstream ipfile;
ofstream opfile;
char c,C 


int amountline = 0;
int amountcha = 0;
int amounttag = 0;
int amountcomment = 0;
cout <<  "Please enter the name of the file you wish to check" << endl;
cin >> file1;


ipfile.open(file1.c_str());
 


cout << " Please enter the file you wish the edited contents to be copied to" << endl;
cin >> file2;

opfile.open(file2.c_str());

while (!ipfile.eof())

	{

ipfile.get(c);
opfile << c;


		

		if(c!='\n' && !ipfile.eof() && c!=' ')
		{
			amountcha++;
		}
		if(c=='\n')
		{
			amountline++;
		}

	      if (c == '<')
   {
    amounttag++;
   }

   
      if ( c =='!')
      {
      amountcomment++;
      }
  

	
  }     
  

C = tolower(c);

cout << c << " " << char (toupper(c)) 






cout << " This file contains :" << amountline << " lines" << endl;
cout << " This file contains :" << amountcha << " charecters" << endl;
cout << " this file has : " << amountcomment<<  " comments " << endl;
cout << " This file contains  : " << amounttag << "tags"   << endl; 















return 0;
}




Fair start, one point to note is that line 66 will count exclamation marks used in punction also.

To output the characters in small your lines 45 and 46 have code between them that check if the character after a tag is small and make it uppercase. Although you'll have to put in extra work later with HTML tags like <a href><src><img> as many of them use multiple values.
Thanks Umz, but I am alittle confused, what exactly should I do with lines 45 and 46. Do you know how to edit line 66 so it will count correctly?

Thanks
You could get the next character. If it is a alpha numeric add one to comments. If it is a bracket > don't add one. That's just a suggestion. Some people code differently than others so you will have to devise a method.
eker676 has a great solution for the commenting.

If you want the program to output all tags in lower case you will have to add code between 45 and 46 that will:

Read in the file and check which tags are uppercase.
Turn these to lower case and output that line.

Then your output file will have only lowercase tags.
Topic archived. No new replies allowed.