Ich muss die Nummern der Schüler eingeben, dann markiert ihr Name dann. Aber wenn ich die Markierungen eintippe, stürzt das Programm ab. Ich weiß nicht warum, wenn ich in die letzte Loop-Funktion eingebe, stürzt es mein Programm ab. Vielleicht weil ich zu viel verschachtelt habe?For Loop-Funktion stürzt bei Eingabe ab
#include <stdio.h>
#include <string.h>
#define NAME_LEN 25
int noOfStud(void);
void listStudents(int noOfStud, char names[][NAME_LEN]);
void options(int noOfStud, double marks[]);
void switchOptions(int noOfStud, double marks[]);
void courseWork1(int noOfStud, double marks[]);
void emptyBuffer(void);
int main(void)
{
int students;
char names[students][NAME_LEN];
double marks[students];
students = noOfStud();
listStudents(students, names);
options(students, marks);
return 0;
}
int noOfStud(void)
{
int students;
printf("Number of students: ");
scanf("%d", &students);
getchar();
return students;
}
void listStudents(int noOfStud, char names[][NAME_LEN])
{
int i;
for(i=0; i<noOfStud; i++)
{
printf("Enter name: ");
scanf("%[^\n]", names[i]);
getchar();
}
}
void options(int noOfStud, double marks[])
{
printf("1. Enter marks for course work 1\n");
printf("2. Enter marks for course work 2\n");
printf("3. Enter makrs for course work 3\n");
printf("4. Display a particular student's marks\n");
printf("5. Supervisor mode\n");
printf("6. Exi program\n");
switchOptions(noOfStud, marks);
}
void switchOptions(int noOfStud, double marks[])
{
char options;
printf("\nPlease enter a number for which choice you want: ");
scanf("%d", &options);
emptyBuffer();
switch(options)
{
case 1:
printf("Thank you for chosing to enter marks for course work 1!\n");
courseWork1(noOfStud,marks);
break;
case 2:
printf("Thank you for chosing to enter marks for course work 2!\n");
break;
case 3:
printf("Thank you for chosing to enter marks for course work 3!\n");
break;
case 4:
printf("work 4");
break;
case 5:
printf("work 5");
break;
case 6:
printf("work 6");
break;
default:
printf("You didn't enter anything");
}
}
void courseWork1(int noOfStud, double marks[])
{
int i;
for(i=0; i<noOfStud; i++)
{
printf("Enter marks: ");
scanf("%d", &marks[i]);
getchar();
}
}
void emptyBuffer(void) /* Empty the keyboard buffer */
{
while(getchar() != '\n')
{
;
}
}
Alles funktioniert gut, bis ich die letzte Loop-Funktion eingeben, es stürzt ab. Habt ihr irgendwelche Ideen warum? Danke, dass Sie mir helfen wollen.
void courseWork1(int noOfStud, double marks[])
{
int i;
for(i=0; i<noOfStud; i++)
{
printf("Enter marks: ");
scanf("%d", &marks[i]);
getchar();
}
}
http://idownvotedbecau.se/nomcve/ – klutt
'Char Namen [Studenten] [NAME_LEN];' sollte nach 'Studenten = noOfStud();' sein. – mch
'scanf ("% d ", & Optionen);' -> 'Optionen' ist vom Typ' char'. Dies sollte 'scanf ("% c ", & Optionen) sein;' –