The first two I can do all right, the following came out clean in Valgrind and produced expected results. I suppose I'm lost on the logic of what I'm trying to do in the end.
Code:
int main()
{
typedef struct foo
{
int x;
} foo;
int *x, *xstart;
foo integer;
integer.x = 5;
printf("should get 25: %d\n", 5*integer.x);
x = (int *) calloc(10, sizeof(int));
xstart = x;
for(x = xstart; x < xstart + 10; ++x)
{
*x += 2;
printf("%d\n", *x);
}
free(xstart);
return 0;
}
So I naively tried something like:
Code:
int main()
{
typedef struct foo
{
int *x;
} foo;
foo array;
int *start;
array.x = (int *) calloc(10, sizeof(int));
start = array.x;
for(array.x = start; array.x < start + 10; ++(array.x))
{
array->x = 1;
printf("%d\n", array->x);
}
free(start);
return 0;
}
and wound up with a disaster.