How to use a calculated value to access array elements

Dears,
i need your help with the following question:

In my code i have an array defined that contains some text to display on a small OLED-Statusdisplay:

char* modustext[7] = {"normal","eins","zwei","drei","vier","fünf","sechs"};

i also have a simple "helper-variable:

int i = 1;

i have no problem to address to access and print/display individual texts from my array, e.g with

Serial.println(modustext[i]);

or all of them with a for...loop.

But, now the problem: as soon as i add any other calculation-process to "i" (even a simple "i++"), the code/the units gets stuck and it wont start correctly anymore.
The code is compiling without error though, and thats why i´m pretty lost here...

Any ideas or hints for me?

Post the code, using code tags, and explain where the problem shows up.

Welcome to the forum

Start by posting a complete sketch that illustrates the problem. It is quite legitimate to use a variable as the index to an array so you are probably doing something odd

Hint... post your code.

Post ALL the code, and any error messages.

Explain what "doesn't work" means: describe what you expected to happen, and what happened instead.

Where is "i" declared?

Note that if "i" is an array index, when modifying it you must avoid going outside of array bounds, or your program is guaranteed to fail.

Actually... we do. It is much easier if to debug if we can see ALL the code.

(post deleted by author)

Please post the code, not your verbiage.

Show the full code, please

Turn on "verbose" compiler messages in preferences. This is actually not valid C/C++, although the Arduino IDE tries to let you get away with it.

char* modustext[6] = {"Normal LS (1 frame)","Intervall (1 sec)","Intervall (2 sec)","Intervall (1 sec)","Burst LS (2 frames)","Burst LS (3 frames)"};

You call update_display() every time when the loop() run. So if you increment the i variable every run of this procedure - it exceed the range of array almost immediately after board starts and then running out of array bounds.
This causes the program to freeze.

(post deleted by author)

(post deleted by author)

Valid C/C++:

const char* modustext[6] = {"Normal LS (1 frame)","Intervall (1 sec)","Intervall (2 sec)","Intervall (1 sec)","Burst LS (2 frames)","Burst LS (3 frames)"};

ln addition, you MUST obey array bounds when modifying index variables.

What should happen when i exceeds the number of array elements? Reset it to zero or just don't increase anymore?
In any case, the code should have such a check

N'mind, Sry, sand in my keyboard.

But we do. There is something going on and it wou,d be waaaaay easier to find out what it is if it were presented in the context of a complete it compiles and we could run it oursefs sketch.

So make a little sketch that demonstrates this problem.

a7

Undefined operation in C/C++, nor is it clear what you intend with that statement.

If it "should be", why do you not fix it in place, rather than adding a useless comment?

Please post last version of the code after fixing all the errors, what the forum was pointed you.

(post deleted by author)

... is an array with 2 elements... but you are using the same index (0-5) that you are using for modustext.