#include <stdio.h> #include <stdlib.h> #include <string.h> #define MAX_LINE_LENGTH 1024 #define NUM_PLAYERS 30 #define NUM_SEASONS 7 typedef struct { char name[100]; int goals; int assists; int fouls; int yellow_cards; int red_cards; } Player; typedef struct { Player players[NUM_PLAYERS][NUM_SEASONS]; } Team; int get_season_index(int year) { return year - 2018; } void read_team_data(const char* filename, Team* team_data) { FILE* file = fopen(filename, "r"); if (!file) { printf("Error opening file %s\n", filename); return; } char line[MAX_LINE_LENGTH]; int season, player_idx = 0; fgets(line, sizeof(line), file); // Skip header line while (fgets(line, sizeof(line), file)) { int season_index = -1; if (sscanf(line, "%d", &season) == 1) { season_index = get_season_index(season); } if (season_index < 0 || season_index >= NUM_SEASONS) { continue; } sscanf(line, "%d,%99[^,],%d,%d,%d,%d,%d", &season, team_data->players[player_idx % NUM_PLAYERS][season_index].name, &team_data->players[player_idx % NUM_PLAYERS][season_index].goals, &team_data->players[player_idx % NUM_PLAYERS][season_index].assists, &team_data->players[player_idx % NUM_PLAYERS][season_index].fouls, &team_data->players[player_idx % NUM_PLAYERS][season_index].yellow_cards, &team_data->players[player_idx % NUM_PLAYERS][season_index].red_cards); player_idx++; } fclose(file); } void display_season_stats(Team* team_data, int season_index) { int total_goals = 0, total_assists = 0, total_fouls = 0, total_yellow_cards = 0, total_red_cards = 0; for (int i = 0; i < NUM_PLAYERS; i++) { total_goals += team_data->players[i][season_index].goals; total_assists += team_data->players[i][season_index].assists; total_fouls += team_data->players[i][season_index].fouls; total_yellow_cards += team_data->players[i][season_index].yellow_cards; total_red_cards += team_data->players[i][season_index].red_cards; } printf("Total Goals: %d\n", total_goals); printf("Total Assists: %d\n", total_assists); printf("Total Fouls: %d\n", total_fouls); printf("Total Yellow Cards: %d\n", total_yellow_cards); printf("Total Red Cards: %d\n", total_red_cards); } void display_all_seasons_stats(Team* team_data) { int total_goals = 0, total_assists = 0, total_fouls = 0, total_yellow_cards = 0, total_red_cards = 0; for (int j = 0; j < NUM_SEASONS; j++) { for (int i = 0; i < NUM_PLAYERS; i++) { total_goals += team_data->players[i][j].goals; total_assists += team_data->players[i][j].assists; total_fouls += team_data->players[i][j].fouls; total_yellow_cards += team_data->players[i][j].yellow_cards; total_red_cards += team_data->players[i][j].red_cards; } } printf("Total Goals: %d\n", total_goals); printf("Total Assists: %d\n", total_assists); printf("Total Fouls: %d\n", total_fouls); printf("Total Yellow Cards: %d\n", total_yellow_cards); printf("Total Red Cards: %d\n", total_red_cards); } void display_player_season_stats(Team* team_data, const char* player_name, int season_index) { int total_goals = 0, total_assists = 0, total_fouls = 0, total_yellow_cards = 0, total_red_cards = 0; int found = 0; for (int i = 0; i < NUM_PLAYERS; i++) { if (strcmp(team_data->players[i][season_index].name, player_name) == 0) { total_goals = team_data->players[i][season_index].goals; total_assists = team_data->players[i][season_index].assists; total_fouls = team_data->players[i][season_index].fouls; total_yellow_cards = team_data->players[i][season_index].yellow_cards; total_red_cards = team_data->players[i][season_index].red_cards; found = 1; break; } } if (found) { printf("Goals: %d\n", total_goals); printf("Assists: %d\n", total_assists); printf("Fouls: %d\n", total_fouls); printf("Yellow Cards: %d\n", total_yellow_cards); printf("Red Cards: %d\n", total_red_cards); } else { printf("Player not found.\n"); } } void display_player_all_seasons_stats(Team* team_data, const char* player_name) { int total_goals = 0, total_assists = 0, total_fouls = 0, total_yellow_cards = 0, total_red_cards = 0; int found = 0; for (int i = 0; i < NUM_PLAYERS; i++) { if (strcmp(team_data->players[i][0].name, player_name) == 0) { for (int j = 0; j < NUM_SEASONS; j++) { total_goals += team_data->players[i][j].goals; total_assists += team_data->players[i][j].assists; total_fouls += team_data->players[i][j].fouls; total_yellow_cards += team_data->players[i][j].yellow_cards; total_red_cards += team_data->players[i][j].red_cards; } found = 1; break; } } if (found) { printf("Total Goals: %d\n", total_goals); printf("Total Assists: %d\n", total_assists); printf("Total Fouls: %d\n", total_fouls); printf("Total Yellow Cards: %d\n", total_yellow_cards); printf("Total Red Cards: %d\n", total_red_cards); } else { printf("Player not found.\n"); } } int main() { Team team_data; int season_choice, specific_player_choice, season_index; char player_name[100]; char team_name[100]; // Ask for team name first printf("Enter the team name: "); scanf("%s", team_name); // Build the file name based on the team name char filename[200]; sprintf(filename, "C:\\Users\\Ahmed\\PycharmProjects\\pythonProject1\\11\\2024\\%s.csv", team_name); // Read the team data read_team_data(filename, &team_data); // Ask for the season choice (specific season or all seasons) printf("Choose season type:\n1. Specific Season\n0. All Seasons\n"); scanf("%d", &season_choice); // Clear the newline character left by scanf getchar(); // This consumes the leftover '\n' from the previous input if (season_choice == 1) { printf("Enter the season year (2018-2024): "); scanf("%d", &season_index); season_index = get_season_index(season_index); printf("Do you want stats for a specific player? (1 for yes, 0 for no): "); scanf("%d", &specific_player_choice); // Clear the newline after reading the integer getchar(); if (specific_player_choice == 1) { printf("Enter player's name: "); fgets(player_name, sizeof(player_name), stdin); // Use fgets player_name[strcspn(player_name, "\n")] = 0; // Remove newline character display_player_season_stats(&team_data, player_name, season_index); } else { display_season_stats(&team_data, season_index); } } else { printf("Do you want stats for a specific player? (1 for yes, 0 for no): "); scanf("%d", &specific_player_choice); // Clear the newline after reading the integer getchar(); if (specific_player_choice == 1) { printf("Enter player's name: "); fgets(player_name, sizeof(player_name), stdin); // Use fgets player_name[strcspn(player_name, "\n")] = 0; // Remove newline character display_player_all_seasons_stats(&team_data, player_name); } else { display_all_seasons_stats(&team_data); } } return 0; } i want to Mpi to this code without affect ot change of its functionlaties