Reputation: 9
This is a relatively simple program for tabulating grades.
My program crashes while trying to complete the last loop, specifically at the last midterm input. Any help here?
#include <stdio.h>
#include <string.h>
#define ARRAYSIZE 2
int main(void)
{
char studentID[ARRAYSIZE][10];
int midterm[ARRAYSIZE];
int fina[ARRAYSIZE];
int i=0;
double overall[ARRAYSIZE];
for (i=0;i<ARRAYSIZE;i++)
{
printf("\nInput Student ID:");
scanf("%s",&studentID[i][10]);
printf("\nInput midterm score:");
scanf("%d",&midterm[i]);
printf("\nInput final score:");
scanf("%d",&fina[i]);
overall[i]=midterm[i]*0.3+fina[i]*0.7;
}
printf("\nStudent ID MidTerm Final Overall\n");
for (i=0;i<ARRAYSIZE;i++)
{
printf("%s%5d%5d%5f",studentID[i][10],midterm[i],fina[i],overall[i]);
}
return 0;
}
The process returned is -1073741819 (0xC0000005). Thanks.
Upvotes: 1
Views: 56
Reputation: 21931
please try this //declaration
int ARRAYSIZE=2;
char studentID[ARRAYSIZE][10];
//Then, you need to enter the string into the array
int i;
for (i=0; i<ARRAYSIZE; i++) {
scanf ("%s" , studentID[i]);
} // in oreder to print them use
for (i=0; i<ARRAYSIZE; i++) {
printf ("%s" , studentID[i]);
}
Upvotes: 0
Reputation: 99
The error is in the final printf statement, specifically 'studentID[i][10]' here you are accessing an element at an illegal index (0 to 9 are legal in your case)
Upvotes: 3