C/array of structure
Expert: Joydeep Bhattacharya - 11/14/2009
Questionsir,
i m pawan getting a problem in the follwing program . my problem is when i ask a user to enter the value for marks it unable to store the value in a[i].marks. what is the problem.
struct student
{
int name[10];
float marks;
}a[2];
void main()
{int i=0;
for(i=0;i<=2;i++)
{
printf("please enter the name of the student \n")
scanf("%s",&a[i].name);
printf("enter the marks of student\n");
scanf("%f",&a[i].marks);
}
}
AnswerHi Pawan
There are many errors in the code u have sent please remove the same and try again
struct student
{
int name[10];
float marks;
}a[2];
void main()
{int i=0;
for(i=0;i<=2;i++)
{
printf("please enter the name of the student \n")
scanf("%s",&a[i].name);
// variable name is declared as an array if int in the structure but you have used %s either change it to char or change %s to %d
printf("enter the marks of student\n");
scanf("%f",&a[i].marks);
}
}
Please let me know if the problem persist still
regards
Joydeep BHattacharya
http://www.scodz.com