So I'm trying to write a program in which I need to enter informations like name, surname, student id, birthday for multiple students . The thing is I can't get it to print the info for all the students. This version of the code I wrote just prints the variables without anything stored in them or with some weird characters. In an earlier version of the script the info I typed in would just overwrite the previous info and it would print just one student's info. I think I need to make some changes in the for loop if I'm not mistaken. If someone could give me a hand, I'd appreciate it.
Here's the code:
#include <stdio.h>
#include <string.h>
#define students 200
typedef struct {
char name[20];
char surname[20];
int studentid[5];
int day[5];
int month[5];
int year[5];
}student;
int main(){
student a[students];
int j;
int n;
int i;
int choice;
for(i=0;i<=students;i++){
printf("\n===========================================================\n");
printf("\n1 Enter info for a student");
printf("\n2 Print all the students");
printf("\n3 End\n");
printf("\n===========================================================\n");
printf("\nChoose something ---> ");
scanf("%d", &choice);
switch(choice)
{
case 1:
printf("Enter name: \n");
scanf("%s", a[students].name);
printf("Enter surname: \n");
scanf("%s", a[students].surname);
printf("Enter student ID: \n");
scanf("%s", a[students].studentid);
printf("Enter day: \n");
scanf("%s", a[students].day);
printf("Enter month: \n");
scanf("%s", a[students].month);
printf("Enter year: \n");
scanf("%s", a[students].year);
break;
case 2:
for(i=0;i<students;i++)
{
printf("\nNome student: %s\nSurname student: %s\nStudent id: %s\nStudent Birthday: %s.%s.%s\n", a[i].name, a[i].surname, a[i].studentid, a[i].day, a[i].month, a[i].year);
}
break;
case 3:
break;
default:
printf("Choose again!\n");
}
}
return 0;
}
Thanks!
#define STUDENTS 20.