Arlind
Arlind

Reputation: 434

Working with arrays inside of arrays of structures

I'm trying to create an array of structures that has an array inside, assign some values to all the elements and print it out but only the first elements of both the arrays get initialized. I'd appreciate some help.

#include <stdio.h>
#include <stdlib.h>
typedef struct el{
    int a[5];
    int id;
} structure;
int main()
{
    int i,j;
    structure kot[5];
    for(i = 0; i < 5; i++)
    {
        scanf("%d", &kot[i].id);
        for(j = 0; i < 5; i++)
        kot[i].a[j] = 1;

    }
  for(i = 0; i < 5; i++)
  {
    printf("Id: %d ", kot[i].id);
    printf(". Array inside: ");
    for(j = 0; j < 5; j++)
        printf("%d ", kot[i].a[j]);

    printf("\n");
  }


    return 0;

}

Upvotes: 0

Views: 60

Answers (1)

haccks
haccks

Reputation: 106012

Change

for(j = 0; i < 5; i++)  

to

for(j = 0; j < 5; j++)

Upvotes: 2

Related Questions