DIGIT-ARC read-only archive · snapshot: July 23, 2026

Need Help In a C Program...Plz Help Me Out

4 posts · originally from https://geek.digit.in/community/threads/need-help-in-a-c-program-plz-help-me-out.122204/

krishnandu.sarkar
krishnandu.sarkar Original post #1
Nov 2, 2009 at 7:03 PM
Define a structure called cricket that will describe the following information:
1. Player_Name
2. Team_Name
3. Batting_Avg

Using cricket declare an array of 50 elements and write a program to read the information about all the 50 players and print a team wise list containing names of players with their batting avg.

Guys I'm stuckd with this team wise printing part.

Say a user entered players of team in this manner
india-india-australia-pakistan-india-pakistan-australia

So I need to print 3 India players thn 2 australia players and than 2 Pak players.

Now a diff user can enter different team name and in different manner

So how shud i sort the array according to team name or simply print it team wise.

Plz help....
shri
shri #2
Nov 4, 2009 at 12:55 PM
Sorting is one option. But involves a little bit of work.

Or you can do this:
Read the team name of the first structure.
Compare this name with the rest of the structures
Print player name when the team names are matching
krishnandu.sarkar
Nov 4, 2009 at 6:31 PM
Or you can do this:
Read the team name of the first structure.
Compare this name with the rest of the structures
Print player name when the team names are matching

Well I tried this.......

But say......I insert the team name in the array in this sequence

Ind-Aus-Pak-Ind-Aus-Pak-Ind-Aus-Pak

Now all Ind gets printed....

Now I'm stuck how to get the Aus from that array and make sure that Ind doesnt gets printed again......
shri
shri #4
Nov 5, 2009 at 9:47 AM
This is a crude solution.

Maintain a flag array say is_printed[MAX_SIZE].
Initially all entries in the array are 0.
When a particular team player name is printed the corresponding index in the is_printed[] array is made 1.

Ex: ind-aus-pak-ind-aus-aus-pak = 7 players
Before printing any : is_printed[] = {0,0,0,0,0,0,0}
After printing ind players: is_printed[] = {1,0,0,1,0,0,0}

Now, during the second iteration, when you need to print the aus players, do a check on the is_printed array and skip the structure for the index having a 1 in the is_printed array. i.e you'll skip the 0th nad the 3rd structure.