converting texts on saved file to uppercase.


This program displays texts from a file but how do i convert all lower case words into upper case and display them on the screen.


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
#include <iostream>
#include <iomanip>
#include <fstream>
#include <string> 

using namespace std;
const int MAXFILENAMESIZE = 80;
void GetANameAndOpenAFile(ifstream & f, char * fn);
void GetNameandOutput (ofstream & of, char * ofn);


int main (void)




{
	
	
	ofstream outputfile;
	char outputfilename [MAXFILENAMESIZE];
	GetNameandOutput(outputfile, outputfilename);
	outputfile.close();	


	ifstream inputfile;
	char filename [MAXFILENAMESIZE];
	string inputline;
	GetANameAndOpenAFile(inputfile,filename);
	
	cout<<"\nThe following should represent the content of road.txt: \n"<<endl;

	while (getline(inputfile, inputline))
	{
		
		cout<< inputline <<endl;
		
}
	inputfile.close();
	
	
	return 0;
	
	
}

void GetNameandOutput (ofstream & of, char * ofn)
{
	cout<<"\nEnter in a input filename: ";
	cin>> ofn;
	of.open(ofn);
	while(!of.is_open())
	{
		cout<<"\nInvalid inputfile name, re-enter: ";
		cin>> ofn;
		of.open(ofn);
		
	}
	
}


void GetANameAndOpenAFile(ifstream & f, char * fn)
{
	cout <<"\nEnter in a output file name to open:  ";
	cin >> fn;
	f.open(fn);
	while(!f.is_open())
	{
		
		cout<<"\nInvalid output file name, re-enter: ";
		cin>> fn;

	
		f.open(fn);
		
	}	
}

Last edited on
1
2
3
4
5
6
7
8
9
10
11
12
13
int main ()
{
  int i=0;
  char str[]="Test String.\n";
  char c;
  while (str[i])
  {
    c=str[i];
    putchar (toupper(c));
    i++;
  }
  return 0;
}


Exemple from this : http://www.cplusplus.com/reference/cctype/toupper/

Hope this helps !
Topic archived. No new replies allowed.