condtions with struct!!

June 9, 2009 at 13:05:32
Specs: Windows Vista
hey can anyone help me ....i did astruct for 10 students and enterd theier names ,number,college,department,level....its easy but theproblem i faced after that is i want to categori each student who has the same college name be printd together so example students n computer they r all groupd together and if i enterd 2 students from bussiness they has to be groupd together can i do???
i tried doing if(std[i].college=="computer")
but it didnt work and tried also if(std[i].college==std[i],college) ofcourse these r inside please help me fast>>>>>

See More: condtions with struct!!

Report •

June 19, 2009 at 16:10:33
C/C++ does not work that way. You can compare std::string objects using ==, but not character arrays which is what I think you are doing.
Do this
if (strcmp(std[i].college, "computer") == 0)
The strcmp function compares two C strings and returns 0 when they are equal.

Report •

June 23, 2009 at 03:10:49
If you aren't comparing strings, then you may be after sorting the struct by whatever property.

For example, sort the struct by college name and then try outputting the result.

Report •

Related Solutions

Ask Question