The men's long jump competition at the 2012 Summer Olympics in London, United Kingdom was held at the Olympic Stadium on 3–4 August.
The data of this competition are written to a file named jump.txt which is attached with the assignment.
This file contains the first names, last names, nationality and distances jumped by athletes in this competition.
Write a C program to do the following: (1) read all data from jump.txt; (2) keeps the data into an array of structure and (3) prints out the names, nationalities, and the distances of the jumpers who exceeded a distance given by the user.
Description of the data file jump.txt file
The first line in the file contains titles. Each other line in the file represents a data of a jumper so that white spaces separate the first name, last name, nationality, and the distance as shown below.
This is jump.txt
FirstName LastName Nationality Result
Aleksandr Menkov Russia 8.09
Aleksandr Petrov Russia 7.89
Alyn Camara Germany 7.72
A sample of the running the program
The data are loaded successfully.
Please enter the distance threshold: 8.10
The jumpers exceeded 8.10 m are:
Marquise Goodwin United States 8.11
Mauro Vinicius da Silva Brazil 8.11 2
#include <stdio.h>
#include <stdlib.h>
int main()
{
char ch, file_name[25]; FILE *aj;
printf("Please Enter The Name Of The File You Wish To See \n"); gets(file_name);
aj = fopen(file_name,"r");
if( aj == NULL )
{
perror("Error! Opening The File, Please Try Again :( \n"); exit(EXIT_FAILURE);
}
printf("The Data From The %s File Is :\n", file_name);
while( ( ch = fgetc(aj) ) != EOF )
printf("%c",ch);
fclose(aj);
return 0;
}