Forums
New posts
Search forums
Members
Current visitors
Log in
Register
What's new
Search
Search
Search titles only
By:
New posts
Search forums
Menu
Log in
Register
Install the app
Install
Forums
Archive
Archive
C Programming
Unseen error
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Reply to thread
Message
[QUOTE="hpy_awad, post: 1693981"] I wrote that example from a book and there is en error in the display module that it does not showing all the records are entered in the input module. I traced with some printf statments without getting the solution . I think the error in the display module loop condition. Thanks #include <stdio.h> //-exercise 7.5.1 - Goal Statistics struct football { char name[30]; char team[30]; int goals; }; main () { struct football player[100]; int option; //initialize player array init_player(player); do { //Display menu of options ; menu(); //Determine users requirements menu_choice(&option); //Perform users specified option switch(option) { case 1: //Enter information for all players player_input(player); break; case 2: //display table for all players goal_table(player); break; case 3: //update specific information for a player goal_update(player); break; case 4: //exit from program break; default://illegal input printf ("\n\n This is not an available option\nAvailable options are 1,2,3,4"); } } while (option !=4); } init_player(player) //------------------ struct football player[]; { int i,j; for (i=0;i<100;++i) { for (j=0;j<30;++j) { player[i].name[j]=' '; player[i].team[j]=' '; } player[i].goals=0; } } menu() //------------------ { system ("clear"); printf("\n\n football system "); printf("\n ------------------- "); printf("\n\n 1- Enter information "); printf("\n\n 2- Display table for all players"); printf("\n\n 3- Update specific information"); printf("\n\n 4- Exit from program "); } menu_choice(opt) //------------------ int *opt; { printf("\n\n Select one of the above (1-4) : "); scanf("%d",opt); //clear screen system("clear"); } player_input(player) //------------------ struct football player[]; { int i; char more; i=-1; do { ++i; //input players name printf("Enter players name : "); input_string(player[i].name); //input players team printf("Enter players team : "); input_string(player[i].team); //input number of goals scored fflush(stdin); printf("Enter number of goals scored: "); scanf("%d",&player[i].goals); printf("\n %-30s %-30s %4d\n",player[i].name,player[i].team,player[i].goals); printf("\n %d I Value inside insert\n ",i); //more players if (i<99) { printf("More playersd to be entered (y/n)---->"); scanf("%s",&more); } } while (more == 'y' && i<99); //Terminate players list if (i<99) player[i+1].goals=-1; } input_string(alpha) //------------------ char *alpha; { int i; i=-1; //Flush the keyboard buffer fflush(stdin); do { ++i; //input a character alpha[i]=getchar(); } while (alpha[i] !='\n' && i<29); //Terminate string alpha[i]='\0'; } goal_table(player) //Display table of goals scored //------------------ struct football player[]; { int i=0; char cont; //Output table headings printf("\n\n Name Team Goals"); printf("\n\n ---- ---- -----"); do { //Output player information printf("\n %d I Value inside display ",i); printf("\n %-30s %-30s %4d\n",player[i].name,player[i].team,player[i].goals); ++i; } while (i<=2); printf("\n\n Press C to continue "); scanf("%s",&cont); } goal_update(player) //update table of goals scored //------------------ struct football player[]; { char name[30]; int i,match,goal; //input players name to be updated printf("Enter name of player"); input_string(name); //Find players record i=0; while ((player[i].goals!=-1)&&(i<100)&&(match=strcmp(name,player[i].name) !=0)) ++i; //Input number of goals to be added printf("Enter number of goals to be added to players account"); scanf("%d",&goal); //Update players record if (match==0) player[i].goals=player[i].goals+goal; else printf("\n\n Player %s is not in the goal table \n",name); }[/i][/i][/i][/i][/i][/i][/i][/i][/i][/i][/i][/i][/i][/i][/i][/i][/i][/i][/i] [/QUOTE]
Verification
Post reply
Forums
Archive
Archive
C Programming
Unseen error
Top