I have a struct as below
typedef struct _someStruct
{
int V1;
char V2[10];
} SomeStruct;
SomeStruct *struct;
int elemNo = FillStruct(&struct);
for (i=0; i<elemNo; i++)
PrintElem(&struct[i]);
Function PrintElem is as below:
void PrintElem(SomeStruct *s)
{
printf("\n\tV1 : %d\n\tV2 : %s\n", s->V1, s->V2);
}
Code fails in the loop from 2’n or 3’rd element.
Any suggestion on what’s wrong?
EDIT:
Actually the PrintElem was (the reasoin I made it this way is the fact that the real struct had about 30 fields with long names, so I made it to make the code readable) :
void PrintElem(SomeStruct *s)
{
printf(
"\n\tV1 : %d"
"\n\tV2 : %s\n",
s->V1, s->V2);
}
I didn’t thought this can make a difference, but it did (actually WAS the key of the problem – see my own answer below)
I just post it hoping it will help someone later.
Thanks all for all suggestions and for your time
The correct form of PrintElem should be
Thank you all for help