simple question on arrays!



 
  *( pArray + i + 1 ) = *( pInternalArray + i );



I am copying one array to another one with a "shift" of 1.
The trouble is:

1
2
3
1) *( pArray + i + 1 )

2) pArray[ i + 1 ]


are NOT good. They make perfect sense but they cause my program to crash. Any alternative?

Thanks a lot for the help!
Clodi
Last edited on
You're going to have to post a bit more of your program... your 2nd option seems to be the right one so something else must be making it crash.
I am afraid that isn't right.
I don't know of a better way of putting it but that way isn't accepted by any compiler. Try with yours if you want.

The thing is:

both

1
2
3
*( pArray + i  )

pArray[ i ]


are perfectly legit.

The +1 fucks things up and I don't know of a better way of doing that. but there must be
Well you've taken the code out of context, so it's really hard for me to tell what's actually going on. I'm also not sure if you have pointers or references or what. Please post some more code.
You are probably just going past the bounds of the array, and accessing memory causing a segmentation fault. Try doing a check to see if "i" points to the end of the array, and then if that is the case point to pArray[0] instead.

Also, options 1) and 2) are both perfectly alright, though option 2 is normally preferred in your case due to readability.
Topic archived. No new replies allowed.