I am using a pointer to a structure like an array. So lets say i have a struct named People. I have: People * person. I am constantly adding to the struct by reallocating space in person for a new person entry. This works well for my purpose. When i set the data fields like person[i].age person[i].name, person[i].height; everything works well. and i print from main as i read just to test. When i try to print the data from another function only my string fields gets messed up. For example age,height,weight, are all person variable declared before and after name in People and print normally. Cant figure out why......:sleep:
void printRec(Rec *rec, int size)
{
int i;
for(i = 0; i < size; i++)
{
printf("%d ",person[i].age);
printf("%s ",person[i].fname); //messed up: prints last char in string
printf("%s ",person[i].lname); //messed up: prints a character not in string
printf("%c ",person[i].gender);
printf("%d ",person[i].height);
//etc
printSeperator();
}
}
Ideas?


Sign In
Create Account


Back to top









