M Mohan Giri In Runtime Messages 144 Apr 26, 2005 #1 How to find a current index value of the array? ie last value's position in array.
C C.Ingram In Runtime Messages 259 Apr 26, 2005 #2 You'll have to keep it stored somewhere. C arrays are just pointers to blocks of memoy (see pointer arithmetic). Say you have a 4 element array [0-3]. Code: char array[] = {'a', 'b', 'c', 'd'}; You could keep track of the current element with an integer or a pointer. Code: int cur_index = 2; /* points to 'c' */ char* cur_index = &array[0]; /* points to 'a' */ cur_index++; /* points to 'b' */ cur_index++; /* points to 'c' */
You'll have to keep it stored somewhere. C arrays are just pointers to blocks of memoy (see pointer arithmetic). Say you have a 4 element array [0-3]. Code: char array[] = {'a', 'b', 'c', 'd'}; You could keep track of the current element with an integer or a pointer. Code: int cur_index = 2; /* points to 'c' */ char* cur_index = &array[0]; /* points to 'a' */ cur_index++; /* points to 'b' */ cur_index++; /* points to 'c' */