You can access any array element inside of an array through a
structure pointer this way :
- for 1 D array :
structure_pointer->array_valiable[index1]
- for 2 D array :
structure_pointer->array_valiable[index1][index2]
so now, you can initialize each member of arrays X , Y and field of structure snake_pos using scanf() this way :
#include <stdio.h>
typedef struct Snake_pos
{
char field[10][10];
int Y[10];
int X[10];
}snake_pos;
void pos_init(snake_pos *pos1)
{
int i,j;
//initializing each member
//of array X
for(i=0;i<10;i++)
scanf("%d",&pos1->X[i]);
//of array Y
for(i=0;i<10;i++)
scanf("%d",&pos1->Y[i]);
//of the two dimensional array field
for(i=0;i<10;i++)
for(j=0;j<10;j++)
scanf(" %c",&pos1->field[i][j]);
//notice the space before %c is to consume white spaces returning from before scanf's
}
int main()
{
snake_pos pos1;
pos_init(&pos1);
return 0;
}
Note : if you want to initialize all members to a single fixed value,
then you can instead of using scanf() in for loop, assign the value
this way :
for(i=0;i<10;i++) //initializes all members with a value of 0
pos1->X[i]=0;