isupper and tolower

Why does this errors? I used structure and i want to display it with all lower case letters but it errors. I used #include<cstring> and the entries are all arrays.

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
void DisplayEntry()
{
	ofstream fout;
	fout.open("c:\\acivity\\student.txt");
	system("cls");
	system("COLOR E");
	char ltr;
	cout << setw(11) << "Student No." << setw(10)
		<< "   Name" << setw(10)
		<< "Course" << setw(10)
		<< "   GPA" << setw(10);

	cout.setf(ios::fixed);
	cout.setf(ios::showpoint);
	cout.precision(2);

	int i = 0;
	for (; i < index; i++){
		cout << endl;
		fout << endl;
		cout << person[i].sn << setw(10);
		fout << person[i].sn << setw(2);
		if (isupper/*this one errors*/ (person[i].name)){
			ltr = tolower/*this too*/(phrase[i].name);
			cout << ltr <<setw(10);
			fout << ltr <<setw(2);
		}
		if (isupper/*and too*/(person[i].course)){
			ltr = tolower/*and too*/(phrase[i].course);
			cout << ltr <<setw(10);
			fout << ltr <<setw(2);
		}
		cout << person[i].GPA << setw(10);
		fout << person[i].GPA << setw(2);
	}
	printf("\nRecords Total:%d\n", i);
	system("pause>0");
	fout.close();
}
Last edited on
Unless there's a different 'isupper' that I don't know about, 'isupper' is declared in cctype and takes a single int as parameter, not a char array. Same with 'tolower'.
I changed it now the person errors.
@maeriden: if it doesn't work, how to change it to lower case?
for example:
char name[100];
and the char name's variable is for example, John John
and it should output
john john
1
2
3
4
5
6
7
8
9
10
11
12
for (int i = 0; i < strlen(person.name); i++){
			if (isupper(person[i].name)){
				ltr = tolower(phrase[i].name);
				cout << ltr << setw(10);
				fout << ltr << setw(2);
			}
		}
		for (int i = 0; i < strlen(person.coursee); i++){
			if (isupper(person[i].course)){
				ltr = tolower(phrase[i].course);
				cout << ltr << setw(10);
				fout << ltr << setw(2);

}
}
Last edited on
isupper and tolower work only with single char. See:

http://www.cplusplus.com/reference/cctype/isupper/?kw=isupper

I'd guess you provided a string.
ohh okay! if it's string, will it work?
ohh wait, i did exactly as it's not supposed to be.. I'm gonna change it
this is my structure
1
2
3
4
5
6
7
struct Student
{
	char sn[15];
	char name[100];
	char course[50];
	int GPA;
};


the displayentry
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
void DisplayEntry()
{
	ofstream fout;
	fout.open("c:\\acivity\\student.txt");
	system("cls");
	system("COLOR E");
	char ltr;
	cout << setw(11) << "Student No." << setw(10)
		<< "   Name" << setw(10)
		<< "Course" << setw(10)
		<< "   GPA" << setw(10);

	cout.setf(ios::fixed);
	cout.setf(ios::showpoint);
	cout.precision(2);

	int i = 0;
	for (; i < index; i++){
		cout << endl;
		fout << endl;
		cout << person[i].sn << setw(10);
		fout << person[i].sn << setw(2);
		for (int i = 0; i < strlen(person.name); i++){
			if (isupper(person[i].name)){
				ltr = tolower(person[i].name);
				cout << ltr << setw(10);
				fout << ltr << setw(2);
			}
		}
		for (int i = 0; i < strlen(person.coursee); i++){
			if (isupper(person[i].course)){
				ltr = tolower(phrase[i].course);
				cout << ltr << setw(10);
				fout << ltr << setw(2);
				/*	cout << person[i].name << setw(10);
				fout << person[i].name << setw(2);
				cout << person[i].course << setw(10);
				fout << person[i].course << setw(2);*/
			}
		}
		cout << person[i].GPA + 10 << setw(10);
		fout << person[i].GPA + 10 << setw(2);
	}
	printf("\nRecords Total:%d\n", i);
	system("pause>0");
	fout.close();
}

it errors the person inside the tolower and isupper
Last edited on
You have to write a function that takes a string and calls isupper/tolower on each character individually.
what do you mean by takes a string?
bool areUpper(const char* str, size_t len);
ohh ok! a separate function for making it to lower case... let me try it... Should be all string? and not array?
how to change it if it's not const char*? It errors if i used the Student person[20] since it's a structure
I wouldn't change the function, since a Student doesn't really have a lowercase equivalent.

I'd make an helper function:
1
2
3
4
5
6
void convertStudentLowercase(Student& s)
{
	//toLower is your function that converts a whole string
	toLower(s.name);
	toLower(s.course);
}
Thank you for your help! I think i did it. :)
Topic archived. No new replies allowed.