Im creating an array of structs and i need to concatenate a string value with the for loop index.
this is how i create the struct:
typedef struct b
{
char title[30];
char author[40];
int year,price;
}
book_t;
then I create an array using malloc:
int m;
printf ("array size:\n");
scanf("%d",&m);
B= (book_t *) malloc (m*sizeof ( book_t));
and then i need to pass values to fill the array in this form: Title_i, Author_i, 1000+i, 3 * i for i=1...m so im using this for loop:
for(i=1;i<=m;i++){
B[i-1].title='title_';
B[i-1].author='author_';
B[i-1].year=1000_i;
B[i-1].price=3*i;
}
any ideas on how can i get the i value of every loop next to the string value for the title and the author field?