Computing.Net > Forums > Programming > condtions with struct!!

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

condtions with struct!!

Reply to Message Icon

Name: computergirl
Date: June 9, 2009 at 13:05:32 Pacific
OS: Windows Vista
Subcategory: C/C++
Comment:

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 ...how 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 aloop....so please help me fast>>>>>



Sponsored Link
Ads by Google

Response Number 1
Name: Zlatko
Date: June 19, 2009 at 16:10:33 Pacific
Reply:

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.


0

Response Number 2
Name: shutat
Date: June 23, 2009 at 03:10:49 Pacific
Reply:

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.


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: condtions with struct!!

How declare structs in VB? www.computing.net/answers/programming/how-declare-structs-in-vb/11174.html

calling c functions from java www.computing.net/answers/programming/calling-c-functions-from-java/2913.html

From C++ to C www.computing.net/answers/programming/from-c-to-c/3732.html