Jan 14, 2015 at 9:05am UTC
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 Jan 14, 2015 at 9:06am UTC
Jan 14, 2015 at 9:15am UTC
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'.
Jan 14, 2015 at 9:18am UTC
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 Jan 14, 2015 at 9:18am UTC
Jan 14, 2015 at 9:19am UTC
ohh okay! if it's string, will it work?
Jan 14, 2015 at 9:23am UTC
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 Jan 14, 2015 at 9:25am UTC
Jan 14, 2015 at 9:31am UTC
You have to write a function that takes a string and calls isupper/tolower on each character individually.
Jan 14, 2015 at 9:53am UTC
what do you mean by takes a string?
Jan 14, 2015 at 10:16am UTC
bool areUpper(const char * str, size_t len);
Jan 14, 2015 at 10:39am UTC
ohh ok! a separate function for making it to lower case... let me try it... Should be all string? and not array?
Jan 14, 2015 at 10:56am UTC
how to change it if it's not const char*? It errors if i used the Student person[20] since it's a structure
Jan 14, 2015 at 11:50am UTC
Thank you for your help! I think i did it. :)