Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- struct user{ //the structure is like a variable type
- //like int, float, char, etc
- char *name; //these are the elements of the structure
- int id;
- float score;
- };
- struct user player[4]; //this is an array of 4 user structs called player
- int main(void){
- int i;
- for(i = 0; i < 4; i++){ //get all the information from the user
- printf("Name: ");
- gets(player[i].name); //like the name
- player[i].id++; //automatically increase the ID
- printf("Score: ");
- scanf("Score: %f", player[i].score); //get an arbitrary score
- }
- printf("ID\tName\tScore\n--\t----\t-----\n");
- for(i = 0; i < 4; i++){ //print out the elements from the structs
- printf("%d\t%s\t%.2f", player[i].id, player[i].name, player[i].score);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement