#include <stdio.h>
int count = 0;//global
struct student{
char name[20];
char surname[20];
int age;
char registrationDate[10];
} v[200];
void addStudents(){
printf("\nJu po shtoni nje student te ri ne liste!\n");
printf("\nShkruani emrin:");
scanf("%s", &v[count].name);
printf("\nShkruani mbiemrin:");
scanf("%s", &v[count].surname);
printf("\nShkruani daten e regjistrimit:");
scanf("%s", &v[count].registrationDate);
printf("\nShkruani moshen:");
scanf("%d", &v[count].age);
printf("\nRegjistrimi u ruajt me sukses.\n");
count ++;
return;
}
void menu (){
printf("\nShtyp 1 per te shtuar student.");
printf("\nShtyp 2 per te shfaqur studentet.");
printf("\nShtyp 3 per menune.");
printf("\nShtyp 0 per te mbyllur programin.");
return;
}
void showStudents(){
int i = 0;
for(i=0; i<=count; i++){
printf("Emri i studentit te: %d: %s\n", i+1, v[i].name);
printf("Mbiemri i studentit te: %d: %s\n", i+1, v[i].surname);
printf("Data e regjistrimit i studentit te: %d: %s\n", i+1, v[i].registrationDate);
printf("Mosha i studentit te: %d: %s\n", i+1, v[i].age);
}
return;
}
main(){
printf("*******************PROGRAM PER LIBRARI NE GJUHEN C***********************\n\n");
menu();
bool cond = true;
while(cond){
int choice;
printf("\n\nShkruani zgjedhjen tuaj: ");
scanf("%d", &choice);
switch(choice){
case 1:
addStudents();
break;
case 2:
showStudents();
break;
case 3:
menu();
break;
case 0:
cond = false;
}
}
}
我只是不知道它为什么会一直崩溃。它打印出第一个学生数据而不是崩溃。因此,如果我添加超过1名学生,它将打印出第一个数据,而不会因为崩溃而打印出其他数据。我正在为学生添加addStudents()函数并使用showStudent()打印他们的数据。任何sugesstion?