need explenatino to why my toupper is not working

So in my code I am trying to obtain first and last name of the user as well as the address city etc. but once obtained I need to make the first and last name uppercase as well as the state my program runs but I guess I am not using the "toupper" correctly can anyone guide to what I am doing wrong pleasw

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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
 #define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <iomanip>
#include <cstring>
#include <cctype>
#include "graph1.h"
using namespace std;

//Prototypes are below:
char* getString(char* prompt);
bool validateName(char* name);
bool validateAddress(char* address);
bool validateCity(char* city);
bool validateState(char* state);
bool validateZip(char* zip);
char* convertToUpper(char* string);
void displayLetter(char* fn, char* ln, char* addr, char* city, char* state, char* zip, int weight);


int main()
 {
	//Variable Declaration/Initialization
	char* firstName = NULL;
	char* lastName = NULL;
	char* address = NULL;
	char* phone = NULL;
	char* city = NULL;
	char* state = NULL;
	char* upperState = NULL;
	char* zip = NULL;
	bool res = false;
	int weight = 0;
	char *upperfirstName = NULL;
	char *upperlastName = NULL;



	//Display graphics window
	displayGraphics();

	//Get the fields - validate based on function
	do
	{
		/*   Get the first name*/
		firstName = getString("Enter First Name: ");

		//validate the name
		res = validateName(firstName);
		upperfirstName = convertToUpper(firstName);


	} while (!res);

	do
	{
		/*   Get the last name*/
		lastName = getString("Enter Last Name: ");

		//validate the name
		res = validateName(lastName);
		upperlastName = convertToUpper(lastName);
	} while (!res);

	do
	{
		//Get the address
		address = getString("Enter Street Address: ");

		//validate the address
		res = validateAddress(address);

	} while (!res);

	do
	{
		//Get the phone
		city = getString("Enter City: ");

		//validate the city 
		res = validateCity(city);

	} while (!res);

	do
	{
		//Get the phone
		state = getString("Enter State: ");

		//validate the phone
		res = validateState(state);
		upperState = convertToUpper(state);

	} while (!res);

	do
	{
		//Get the zipcode
		zip = getString("Enter Zipcode: ");

		//validate the zipcode
		res = validateZip(zip);

	} while (!res);


	cout << endl << endl << endl;

	cout << "Enter Weight";
	cin >> weight;



	//Display the fields
	displayLetter(firstName, lastName, address, city, state, zip, weight);

	return 0;
}




char* getString(char* prompt)
{
	char* cptr = NULL;
	char buffer[255];
	cout << prompt;

	cin.getline(buffer, sizeof(buffer));
	cptr = new char[strlen(buffer) + 1];

	strcpy(cptr, buffer);
	return (cptr);



}

bool validateName(char* name)
{
	int i = 0;
	//for to validate the name 
	for (i = 0; name[i] != NULL; i++)
	{
		if (!isalpha(name[i]))
			return false;
		



	}
}




bool validateAddress(char* address)
{
	int i = 0;
	//for to validate the name 
	for (i = 0; address[i] != NULL; i++)
	{
		if ((!isalnum(address[i])) && (!isspace(address[i])))

			return false;
	}
}






bool validateCity(char* city)
{
	int i = 0;
	//for to validate the name 
	for (i = 0; city[i] != NULL; i++)
	{
		if (!isalpha(city[i]) && isupper(!city[0]))
			return false;


	}

}
bool validateState(char* state)
{
	int i = 0;
	//for to validate the name 
	for (i = 0; state[i] != NULL; i++)
	{
		if (!isalpha(state[i]))
			return false;



	}

}
bool validateZip(char* zip)
{
	int i = 0;
	//for to validate the name 
	for (i = 0; zip[i] <6; i++)
	{
		if (!isdigit(zip[i]))


			return false;

	}

}



char* convertToUpper(char* string)
{
	int i;

	//for loop use to conver into uppercase 
	for (i = 0; string[i] != NULL; i++)
	{
		if (!isupper(string[i]))
		{
			toupper(string[i]);
			
		}
	}
	return string;

}
void displayLetter(char* first, char* last, char* addr, char* city, char* upperState, char* zip, int weight)
{
	int x = 525, y = 20;
	double cost;
	int x1 = 200, y1 = 385, width = 290, height = 85;
	displayBMP("envelope.bmp", 0, 0);
	displayBMP("returnAddress.bmp", 43, 26);
	gout << setPos(315, 210) << first << endg;
	gout << setPos(365, 210) << last << endg;
	gout << setPos(315, 220) << addr << endg;
	gout << setPos(315, 230) << city << endg;
	gout << setPos(385, 230) << upperState << endg;
	gout << setPos(410, 230) << zip << endg;


	for (int i = 0; i < weight; i++)
	{
		displayBMP("stamp.bmp", x, y);




		if (i == 2)
		{
			x = 600;
			y = y + 80;
		}

		x = x - 75;


		cost = weight*0.47;

		gout << setPos(x1 + 10, y1 + 20) << "Weight: " << weight << " ounces" << endg;
		gout << setPos(x1 + 10, y1 + 40) << "Cost Of First Class Stamp: 47 Cents" << endg;
		gout << setPos(x1 + 10, y1 + 60) << "Total Mailing Cost: $" << cost << endg;

		drawLine(x1, y1, (x1 + width), y1, 1);//top line across
		drawLine(x1, y1, x1, (y1 + height), 1);//left vertical line
		drawLine((x1 + width), (y1), (x1 + width), (y1 + height), 1);//right vertical line
		drawLine((x1), (y1 + height), (x1 + width), (y1 + height), 1);//bottom line across



	}
}
Line 226 toupper(string[i]);
you call the function toupper() but don't do anything with the value returned by the function. You should assign the result to some variable. I suggest
string[i] = toupper(string[i]);
Ok thanks Chervil that worked I can't believe it was that simple but if I could quick question if for example on the name I just wanted the First letter to just be capatalized how would I go about doing that?
Well, the first letter would be string[0], you wouldn't need a loop for that. Though if the string was already upper case in whole or in part, you might want to convert the string to lower case first, then change the first character to upper.

Topic archived. No new replies allowed.