Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!caen!uflorida!kluge!serss0!id8rld06 From: id8rld06@serss0.fiu.edu (Michael N Johnston) Newsgroups: comp.lang.c Subject: Re: Pointer and integer addition Message-ID: <3111@kluge.fiu.edu> Date: 31 Mar 91 04:48:13 GMT References: <8334@umd5.umd.edu> Sender: news@kluge.fiu.edu Organization: Florida International University, Miami Lines: 36 >struct foo { >unsigned short recsize; >unsigned short num; >char info [24]; >byte flags; >char filename[1] >}; >Where, foo.filename is a placeholder for a variable length string. >After I process one record, I'd like to just increment the pointer to >point to the next record. What I'd like to do is: >fooptr += fooptr->recsize; >However, the compiler I'm using increments the pointer by >recsize * sizeof (struct foo). This is probably correct. If you are declaring foo_ptr as struct foo *foo_ptr; then this is indeed correct operation. What you need to do to incrment foo_ptr to point to the next record is (assuming foo_ptr is pointing to an array of struct foo): ++foo_ptr; If you plan to store a char array in filename DON'T. Use char *filename and point this to your actual array. Using your origional declaration and doing something like strcpy(foo_ptr->filename, "abcde") will lead to disaster. Good Luck, Mike -- ==================================================================== Michael Johnston id8rld06@serss0.fiu.edu or