include<stdio.h>

include<conio.h>

void main()
{
struct student
{
int id;
char name[20];
char sex;
int mid;
int final;
int total=mid+final
};
int i
struct student b [19];
for(i=0;i<20;i++);
{
printf("student %d enter your details\n\n",i+1);
printf("enter your id");
scanf("%d",&b.id);
printf("enter your name\n");
fflush(stdin);
scanf("%s",&b.name);
printf("enter your sex\n");
fflush(stdin);
scanf("%c",&b.sex");
printf("enter mid term score and final");
fflush(stdin);
scanf("%d%d",&b.mid,&b.final);
}
for(i=0;i<20;i++)
{
print("%d%s%c",b.id,b.name,b.sex);
}
getch();
}

THERE IS ACTUALLY NO NEED OF DECLARING STRUCT BEFORE MAIN
you can declare it as

 struct student
  {
    int id;
    char name[20];
    char sex;
    int mid;
    int final;
    int total;
  }b[19];

after void main()
and you cannot declare int total=mid+final; this is wrong
The code has many errors.

MOVING IN for loop first:

=> In for loop, when you are using scanf(), you have to declare for which student you are writing the details.
i.e.

scanf("%d",&b[i].id);

instead of

scanf("%d",&b.id);

=> for scanning a character array, i.e.a string(it applies for a character too), there is no need of using "&" you can write as,

scanf("%s",b[i].name);
scanf("%c",b[i].sex);

=>simillarly, for printing,

printf("%d%s%c",b[i].id,b[i].name,b[i].sex);

=> And finally!!! in 11th line from last, delete the inverted commas after sex.

hope you got it now!!!! :) :)

This article has been dead for over six months. Start a new discussion instead.