Hello, everyone. I wrote a program that use a struct to represent an athlete. The program allocates memory for an array of 5 Athletes, and, soon after I enter the fourth data (height) for the first athlete, I get the message "runtime Error R6002 - floating point support not loaded". The program doesn't reach the line where __LINE__ would be printed. What am I doing wrong? Thanks in advance.
Code:
#include <stdio.h>
#include <stdlib.h>
typedef struct athlete {
char name[ 100 ];
char sport[ 100 ];
double height;
int age;
} Athlete;
void sort_array_of_athletes_in_place( Athlete **array );
int main( void )
{
Athlete *athleteArray = malloc( 5 * sizeof( Athlete ) );
unsigned int i = 0;
unsigned int j;
while ( i < 5 )
{
printf( "Enter the name of athlete %d: ", ( i + 1 ) );
fgets( athleteArray[ i ].name, 100, stdin );
fflush( stdin );
j = 0;
while ( *( athleteArray[ i ].name + j ) != '\0' )
{
++j;
}
*( athleteArray[ i ].name + j - 1 ) = '\0';
printf( "Enter the sport of athlete %d: ", ( i + 1 ) );
fgets( athleteArray[ i ].sport, 100, stdin );
fflush( stdin );
j = 0;
while ( *( athleteArray[ i ].sport + j ) != '\0' )
{
++j;
}
*( athleteArray[ i ].sport + j - 1 ) = '\0';
printf( "Enter the age of athlete %d: ", ( i + 1 ) );
scanf( "%d", &athleteArray[ i ].age );
fflush( stdin );
printf( "Enter the height of athlete %d: ", ( i + 1 ) );
scanf( "%lf", &athleteArray[ i ].height );
fflush( stdin );
//DEBUG:
printf( "Line %d.\n", __LINE__ );
//ENDDEBUG
putchar( '\n' );
++i;
}
sort_array_of_athletes_in_place( &athleteArray );
printf( "Athletes by name, from the oldest to the youngest:\n" );
i = 0;
while ( i < 5 )
{
printf( "%s\n", athleteArray[ i ].name );
++i;
}
}
void sort_array_of_athletes_in_place( Athlete **array )
{
Athlete temp;
unsigned int i;
unsigned int j;
for ( i = 0 ; i < 4 ; ++i )
{
for ( j = 0 ; j < 4 ; ++j )
{
if ( ( *array[ j ] ).age < ( *array[ j + 1 ] ).age )
{
temp = *array[ j ];
*array[ j ] = *array[ j + 1 ];
*array[ j + 1 ] = temp;
}
}
}
}