C Programming For Dummies by Unknown

C Programming For Dummies by Unknown

Author:Unknown
Language: eng
Format: epub
ISBN: 9781119740261
Publisher: Wiley
Published: 2020-10-06T00:00:00+00:00


int main()

{

struct scores

{

char name[32];

int score;

};

struct scores player[4];

int x;

for(x=0;x<4;x++)

{

printf("Enter player %d: ",x+1);

scanf("%s",player[x].name);

printf("Enter their score: ");

scanf("%d",&player[x].score);

}

puts("Player Info");

printf("# Name Score
");

for(x=0;x<4;x++)

{

printf("%d %s %5d
",

x+1,player[x].name,player[x].score);

}

return(0);

}

Exercise 14-6: Type the source code from Listing 14-3 into your editor. Build and run the program.

Exercise 14-7: Add code to Listing 14-3 so that the display of structures is sorted with the highest score listed first. Yes, you can do this. Sorting an array of structures works just like sorting any other array. Review Chapter 12 if you suddenly lose your nerve.

Here’s a hint, just because I’m a nice guy. Line 28 of my solution looks like this:

player[a]=player[b];

You can swap structure array elements just as you can swap any array elements. You don’t need to swap the structure variable’s members.



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.