Ok so here is my code
#include <stdio.h>
#include <string.h>
int main () {
char names[10][20];
int year[10], i, pos;
float mo[10], max=-1;
for (i=0; i<10; i++) {
do {
printf("Please enter your name:\n");
gets(names[i]);
if (strlen(names[i]) > 19)
printf("The name can contain a maximum of 19 characters!\n");
} while (strlen(names[i]) > 19);
do {
printf("Please enter your year of study:\n");
scanf("%d", &year[i]);
if (year[i]<1 || year[i]>5)
printf("Incorrect value! Accepted values are 1-5\n");
} while (year[i]<1 || year[i]>5);
do {
printf("Please enter your average score:\n");
scanf("%f", &mo[i]);
if (mo[i]<5 || mo[i]>10)
printf("Incorrect value! Accepted values are 5-10\n");
} while (mo[i]<5 || mo[i]>10);
if (mo[i]>max)
max=mo[i];
pos=i;
}
printf("The student with the highest score is %s with %f. His/Her year of study is %d\n", names[pos], max, year[pos]);
}
I know that i should avoid gets but this was the recomended by my teacher. I also tried
scanf ("%[^\n]%*c", names[i]);
But i get the same problem. It reads the first name, but all the others not.