I need to know why this prints \"Student Name:\" twice when executing the progra
ID: 3545951 • Letter: I
Question
I need to know why this prints "Student Name:" twice when executing the program. Help me fix it and you get the points.
#include <stdio.h>
#include <cstring>
void print_array(char str[20][20], int number) {
int i;
for (i=0; i < number; i++) {
printf("%s ", str[i]);
}
printf("--- ");
}
void main() {
int students, assignments;
char names[20][20];
do {
printf("How many students are there (between 1 and 20)?");
scanf("%d", &students);
if (students < 1 || students > 20)
printf ("Number of students must be between 1 and 20. ");
} while (students < 1 || students > 20);
do {
printf("How many assignments are there (between 1 and 10)?");
scanf("%d", &assignments);
if (assignments < 1 || assignments > 10)
printf ("Number of assignments must be between 1 and 10. ");
} while (assignments < 1 || assignments > 10);
int i;
for(i=0; i < students; i++){
printf("Student name:");
fgets(names[i], 20, stdin);
}
print_array(names, students);
}