C programing only Use this user-defined structure typedef struct indy_winners_s
ID: 3706448 • Letter: C
Question
C programing onlyUse this user-defined structure typedef struct indy_winners_s { char driver[50]; int year; int cha_number; int speed; } indy_winners_s; You are given a data file that contains a list of Indianapolis 500 Race Winners> Each line in the file pertains to a specific winner, with data seperated by spaces; for example: 1973 Gordon Johncock STPDoubleOilFilter 20 159 1947 Mauri Rose BlueCrownSparkPlug 27 116 2003 Gil deFerran MalboroTeamPensake 6 126 1986 Bobby Rahal Budweiser 3 171
Each driver has a first name, and a last name, seperated by space. The team names have been reduced to one-word, so there are no spaces in team names. Write c program that reads the data into a structure array of type winners. For example using the example data above, the first element of your array would contain: driver Gordon Johncock team STPDouble car_number speed Once data is loaded into an array, print out data for that TEAM only Sample Code Execution: Which team would you like to see? Peugeot Year, Driver Team Care Number Speed 1919, Howdy Wilcox Peugeot 1916, Duri Resta Peugeot and etc C programing only
Use this user-defined structure typedef struct indy_winners_s { char driver[50]; int year; int cha_number; int speed; } indy_winners_s; You are given a data file that contains a list of Indianapolis 500 Race Winners> Each line in the file pertains to a specific winner, with data seperated by spaces; for example: 1973 Gordon Johncock STPDoubleOilFilter 20 159 1947 Mauri Rose BlueCrownSparkPlug 27 116 2003 Gil deFerran MalboroTeamPensake 6 126 1986 Bobby Rahal Budweiser 3 171
Each driver has a first name, and a last name, seperated by space. The team names have been reduced to one-word, so there are no spaces in team names. Write c program that reads the data into a structure array of type winners. For example using the example data above, the first element of your array would contain: driver Gordon Johncock team STPDouble car_number speed Once data is loaded into an array, print out data for that TEAM only Sample Code Execution: Which team would you like to see? Peugeot Year, Driver Team Care Number Speed 1919, Howdy Wilcox Peugeot 1916, Duri Resta Peugeot and etc
Use this user-defined structure typedef struct indy_winners_s { char driver[50]; int year; int cha_number; int speed; } indy_winners_s; You are given a data file that contains a list of Indianapolis 500 Race Winners> Each line in the file pertains to a specific winner, with data seperated by spaces; for example: 1973 Gordon Johncock STPDoubleOilFilter 20 159 1947 Mauri Rose BlueCrownSparkPlug 27 116 2003 Gil deFerran MalboroTeamPensake 6 126 1986 Bobby Rahal Budweiser 3 171
Each driver has a first name, and a last name, seperated by space. The team names have been reduced to one-word, so there are no spaces in team names. Write c program that reads the data into a structure array of type winners. For example using the example data above, the first element of your array would contain: driver Gordon Johncock team STPDouble car_number speed Once data is loaded into an array, print out data for that TEAM only Sample Code Execution: Which team would you like to see? Peugeot Year, Driver Team Care Number Speed 1919, Howdy Wilcox Peugeot 1916, Duri Resta Peugeot and etc Use this user-defined structure typedef struct indy_winners_s { char driver[50]; int year; int cha_number; int speed; } indy_winners_s; You are given a data file that contains a list of Indianapolis 500 Race Winners> Each line in the file pertains to a specific winner, with data seperated by spaces; for example: 1973 Gordon Johncock STPDoubleOilFilter 20 159 1947 Mauri Rose BlueCrownSparkPlug 27 116 2003 Gil deFerran MalboroTeamPensake 6 126 1986 Bobby Rahal Budweiser 3 171
Each driver has a first name, and a last name, seperated by space. The team names have been reduced to one-word, so there are no spaces in team names. Write c program that reads the data into a structure array of type winners. For example using the example data above, the first element of your array would contain: driver Gordon Johncock team STPDouble car_number speed Once data is loaded into an array, print out data for that TEAM only Sample Code Execution: Which team would you like to see? Peugeot Year, Driver Team Care Number Speed 1919, Howdy Wilcox Peugeot 1916, Duri Resta Peugeot and etc Use this user-defined structure typedef struct indy_winners_s { char driver[50]; int year; int cha_number; int speed; } indy_winners_s; You are given a data file that contains a list of Indianapolis 500 Race Winners> Each line in the file pertains to a specific winner, with data seperated by spaces; for example: 1973 Gordon Johncock STPDoubleOilFilter 20 159 1947 Mauri Rose BlueCrownSparkPlug 27 116 2003 Gil deFerran MalboroTeamPensake 6 126 1986 Bobby Rahal Budweiser 3 171
Each driver has a first name, and a last name, seperated by space. The team names have been reduced to one-word, so there are no spaces in team names. Write c program that reads the data into a structure array of type winners. For example using the example data above, the first element of your array would contain: driver Gordon Johncock team STPDouble car_number speed Once data is loaded into an array, print out data for that TEAM only Sample Code Execution: Which team would you like to see? Peugeot Year, Driver Team Care Number Speed 1919, Howdy Wilcox Peugeot 1916, Duri Resta Peugeot and etc
Explanation / Answer
NOTE: a charctar array for team name is not define in user define structure while giving sample data input of first line you have used term "team SPdouble". Assuming the content of structure a typo error, i have added one more character array to store team name. if you want answer in any other way please explain in comment section
PLEASE CHANGE FILE NAME TO THE FILE YOU WANT TO TEST WITH.
.---------------------------------------------->>CODE<--------------------------------------
#include <stdio.h>
#include <string.h>
typedef struct indy_winners_s {
char driver[50];
char team[50];
int year;
int car_number;
int speed;
} indy_winners_s;
int main()
{
FILE *fp;
fp= fopen("Indianapolis.txt","r");//file opening, please change file name accordingly
indy_winners_s data[500]; //declaring array of struct to store the data from file
int i=0,n;
while(!feof(fp)) // run until file ends
{
char temp[20];
fscanf(fp,"%d %s %s %s %d %d",data[i].year,data[i].driver,temp,data[i].team,data[i].car_number,data[i].speed);
strcat(data[i].driver," "); //to append driver name in one array
strcat(data[i].driver,temp);
i++;
}
char teamname[50];
fclose(fp);
n=i;
printf("Which team would you like to see? ");
scanf("%s",teamname);
printf("Year, Driver Team Car Number Speed");
for(i=0;i<n;i++)
{
if(strcmp(teamname,data[i].team)==0)
printf("%d %s %s %d %d ",data[i].year,data[i].driver,data[i].team,data[i].car_number,data[i].speed);
}
return 0;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.