I am new to pointers and trying to use a pointer to the structure. But after the first entry, my program crashes. Kindly assist me.
Here's the structure definition:
struct students{//structure students definition
char name[20];
char RegNo[15];
char CourseUnit[10];
int score;
char grade;
};
The grade should not be entered by the user but instead computed by the program.
Here's my code so far I have written:
int main()//start of main
{
struct students *myStudPtr,myStud[SIZE];
myStudPtr=&myStud[SIZE];
int i;//declare variables
int count;
printf("How many students do you want to deal with?\n");
scanf("%d",&i);//number of entries
for(count=1;count<=i;count++) {
printf("Enter student's name\n");
scanf("%s",&(*myStudPtr).name);
printf("Enter the student's registration number\n");
scanf("%s",&(*myStudPtr).RegNo);
printf("Enter the course unit\n");
scanf("%s",&(*myStudPtr).CourseUnit);
printf("Enter the marks scored\n");
scanf("%d",&(*myStudPtr).score);
}
printf("NAME\tREGISTRATION\t\tCOURSE UNIT\tSCORE\t\tGRADE\n");//tabulates the output
printf("%s\t", myStudPtr->name);
printf("%s\t\t", myStudPtr->RegNo);
printf("%s\t", myStudPtr->CourseUnit);
printf("%d\t\t", myStudPtr->score);
if(myStudPtr->score>100) {
printf("Invalid\n");
} else if(myStudPtr->score<40) {
printf("FAIL\n");
} else if(myStudPtr->score<50) {
printf("D\n");
} else if(myStudPtr->score<60) {
printf("C\n");
} else if(myStudPtr->score<70) {
printf("B\n");
} else if(myStudPtr->score>70) {
printf("A\n");
} else {
printf("Invalid");
}
return 0;
}
Kindly assist.Thanks in advance.