I was trying to learn how structures are passed between functions and I wrote a program where there is an array of structure and structure itself has an array of integers.It is compiling properly but when I run it,the program is not expecting more than 4 values.I dont know what the error is?
#include<stdio.h>
#include<stdlib.h>
typedef struct
{
char bname[10];
int ssn[3];
} book;
void accept(book k[], int n);
void print(book k[], int n);
int main()
{
book a[2];
accept(a, 2);
print(a, 2);
return 0;
}
void accept(book k[], int n)
{
int i, j;
for (i = 0; i < n; i++)
{
for (j = 0; j < 3; i++)
{
scanf("%d\n", &k[i].ssn[j]);
}
scanf("%s\n", k->bname);
}
}
void print(book k[], int n)
{
int i, j;
for (i = 0; i < n; i++)
{
for (j = 0; j < 3; j++)
{
printf("%d\n", k[i].ssn[j]);
}
printf("%s\n", k->bname);
}
}