Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

SOLVED: How can move to a pointer position directly without use ++ operator?

Rubén Pozo:

I'm working with a pointer to a structure. I want to know if is posible move directly to a specific position without use ++ operator.


#include
#include

#define ARRAY_SIZE 10

struct dummy{
int id;
char buffer[10];
};

typedef struct dummy dummy_struct;

int main()
{
int i=0;
dummy_struct *ds = malloc(sizeof(dummy_struct)*ARRAY_SIZE);
dummy_struct *iterator = ds;

for(i=0;i iterator->id = i;
sprintf(iterator->buffer,"%d",i);
iterator++;
}

iterator = ds;

for(i=0;i printf("%d:%s:%p\n",iterator->id,iterator->buffer,iterator);
iterator++;
}

// I want to access directly to 5th position

iterator = ds + (sizeof(dummy_struct)*5);

printf("5th position %d:%s:\n",iterator->id,iterator->buffer,iterator);

return 0;
}

iterator = ds + (sizeof(dummy_struct)*5); is not working. I will appreciate any suggestion.



Posted in S.E.F
via StackOverflow & StackExchange Atomic Web Robots
This Question have been answered
HERE


This post first appeared on Stack Solved, please read the originial post: here

Share the post

SOLVED: How can move to a pointer position directly without use ++ operator?

×

Subscribe to Stack Solved

Get updates delivered right to your inbox!

Thank you for your subscription

×