struct std {
char name[20];
float marks;
} marklist[30];
char word[20];
void main()
{
int
n,
i,
wordlen,
namelen,
highest;
printf( "Enter the students' names
and marks (end with a dot)\n" );
n = 0;
namelen = 0;
while( n < 30 )
{
scanf( "%s",
word );
if( strcmp(
word, "." ) == 0 )
break;
else if( sscanf(
word, "%f", &(marklist[n].marks) ) == 1 )
{
if( namelen == 0 )
break; /* marks without
name, incorrect */
else
{
n = n + 1;
namelen = 0; /* for the next name */
}
}
else
{
wordlen = strlen( word );
if( namelen == 0 )
{
namelen = wordlen;
if( wordlen < 30 )
strcpy( marklist[n].name, word );
else
break; /* too long first name, reject */
}
else
{
if( (namelen + wordlen) < (30 - 1) )
{
strcat( marklist[n].name, " " );
strcat( marklist[n].name, word );
namelen = namelen + wordlen + 1;
}
/* skip too long words, take short words if any follows */
}
}
}
if( n > 0 )
{
highest =
0;
i = 1;
while( i <
n )
{
if( marklist[highest].marks < marklist[i].marks )
highest = i;
i = i + 1;
}
printf( "Highest marks %f obtained by %s\n", marklist[highest].marks,
marklist[highest].name );
}
else
printf( "No
records\n" );
}