You are here:

C/array of structure

Advertisement


Question
sir,
    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);
}
}


Answer
Hi 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

C

All Answers


Answers by Expert:


Ask Experts

Volunteer


Joydeep Bhattacharya

Expertise

Ability to solve C and Data Structure problems and puzzles with simple and easy to understand logic.

Experience

C, C++, Java, Data Structure, PHP, Web Designing

Organizations
http://www.scodz.com Designation: webmaster

Publications
http://www.scodz.com

Education/Credentials
Master of Computer Applications

Past/Present Clients
http://analysingc.50webs.com http://www.funforu.com

©2012 About.com, a part of The New York Times Company. All rights reserved.