Note that there are some explanatory texts on larger screens.

plurals
  1. POIncrementing array values - Arduino
    primarykey
    data
    text
    <p>I'm trying to increment some array values:</p> <pre><code>int counter[] = {0,0,0,0,0,0,0,0}; </code></pre> <p>If the value of the number in position 0 reaches 25, then the value in position 1 is incremented by 1, and position 0 reset to 0. And so on - when index position 2 reaches 25 it increments position 3 by 1, and resets it's own value to 0.</p> <p>I'm doing some base26 incrementing - generating all the combinations of letters for a given number of letters. Ideally I'd like this to work infinitely (in theory) - a new array index is appended when the last value reaches 25.</p> <p>I'm working on the project which this previous question relates to - might clear up what I'm trying to do: <em><a href="https://stackoverflow.com/questions/4610093/every-permutation-of-the-alphabet-up-to-29-characters">Every permutation of the alphabet up to 29 characters?</a></em></p> <p>Here's the code I have at the minute:</p> <pre><code>// Set the variables. String neologism; int counter[] = {0,0,0,0,0,0,0,0}; String base26[] = {"a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"}; void setup() { // Initialize serial communication: Serial.begin(9600); } void loop() { int i = 0; // Reset or increment the counter. if (counter[i] == 25) { counter[i] = 0; counter[i+1]++; } else { counter[i]++; } neologism = letters(counter[i]); Serial.print(neologism+'\n'); delay(100); i++; if(i&gt;7) { i=0; } } String letters(int counter) { String newword; for(int i=0; i &lt;= 7; i++) { newword += base26[counter]; } return newword; } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload