Separate array and save in strings for later use

0

I have a loop for * which counts from 1 to 8 and saves to an array call str , but I I would like that when the variable str reaches 8 the value of str[i] in the array str_line[b]

Example:

  • The for loop starts
  • You store the value in% with%
  • When i = 8 stores everything that has been accumulated so far in str[i] and saves in str[i]
  • Increases str_line[b]
  • Set the b and start all over again
  • When i is in 5 , for loop b
  • The program would do this during its execution:

    str[1] = 1
    str[2] = 11
    str[3] = 111
    str[4] = 1111
    str[5] = 11111
    str[6] = 111111
    str[7] = 1111111
    str[8] = 11111111
    
    Guarda tudo que estiver em 'str[8]' em 'str_linha[1]';
    
    Incrementa o 'b*'
    
    E repete isso até o laço FOR fizer isso 5 vezes.
    

    I am not able to transfer the value of for to str[8] , how can I do it?

    My code so far:

    char str[9];
    char str_line[6];
    int i;
    int b;
    
    for(i = 0; i < 8; i++)
    {
       str[i] = '0' + i;
       Serial.println(str);
    
    
       if(i = 8)
       {
           //Aqui guardaria o valor em str_line.
    
           //Zera o ponteiro e começa a contagem do FOR desde o inicio
           i = 0;
    
       elseif(b = 5)
       {
           //Para o laço FOR
       }
     }
    
    }
    
        
    asked by anonymous 20.04.2016 / 14:05

    1 answer

    1

    I find this code weird, I would do it differently, but come on:

    char str[9];
    char str_line[6][9];
    int i;
    int b = 0;
    for (i = 0; i < 8; i++) {
       str[i] = '0' + i;
       Serial.println(str);
       if (i == 8) {
           str[8] = '
    char str[9];
    char str_line[6][9];
    int i;
    int b = 0;
    for (i = 0; i < 8; i++) {
       str[i] = '0' + i;
       Serial.println(str);
       if (i == 8) {
           str[8] = '%pre%';
           memcpy(str_line[b], str, 9);
           i = 0;
           b++;
           if (b == 5) {
               break;
           }
       }
    }
    
    '; memcpy(str_line[b], str, 9); i = 0; b++; if (b == 5) { break; } } }

    I did not test, but basically this is it. There may be other undetected errors. I do not know exactly what the expected result is.

        
    20.04.2016 / 14:16