I have a pointer pointed to an array and is incremented every time a data is read. Each data is of different length and so I use strlen to jump the pointer. How do I reset the pointer back to its starting address?! Thank you for your help.
When you open an os. File and read some or all its contents, the file pointer offset will be set to the last line that was read. If you want to reset the pointer to the beginning of the file, you need to call the Seek() method on the file. Thanks for reading, and happy coding!
fseek(fptr, 0, SEEK_SET); to reset the pointer to the start of the file.
Store the original value in another pointer, then assign that stored value back.
char* original;
char* current;
current = wherePointerShouldPointAtStart();
original = current;
while( someCondition() ) {
usePointer( ¤t );
}
current = original;
I think your best bet would be to simply make a copy of the pointer, then whenever you need to reference the first element you just use the new copy. Example:
int *array = ..;
int *beginning = array;
If you need to reference the first element, or even copy the starting address to the original pointer, you just use the beginning pointer.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With