-
Run Time Error
Why I will get a run time error message?Can some body pls show the wrong place?
#include<stdio.h>
#define MAX_STU 50
typedef struct{
int id;
double gpa;
} student_t;
void scan_student (student_t *s)
{
printf("\nEnter student id>");
scanf("%d", &s->id);
printf("\nEnter student gpa>");
scanf("%lf", &s->gpa);
}
main()
{
student_t stulist[MAX_STU];
int i;
for(i=0; i<MAX_STU; ++i)
scan_student (&stulist[i]);
for(i=0; i<MAX_STU; ++i)
printf("%d\n", stulist[i].id);
}
-
Works fine here. What's the error message you are getting?
-
I got the same run-time error.
Don't know why but I solved it by changing %lf to %ld or scanning the gpa in a tmp variable:
Code:
scanf("%ld ", &s->gpa);
or
void scan_student (student_t *s)
{
double tmp;
printf("\nEnter student id>");
scanf("%d", &s->id);
printf("\nEnter student gpa>");
scanf("%lf", &tmp);
s->gpa = tmp;
}
b.t.w. shaik786, the error message is:
runtime error R6002
- floating point not loaded
Using Windows NT, VC++ 6.0
-
why this will happen? can advance pls explain?
-
www.rt.com/man/ Lookup scanf(), then look at the format modifiers it accepts.