Expected primary-expression before

hii i have this problem and I can't fixe it can anyone help me

where is "i" defined

it would have saved time if you posted the complete error msg, including the line number

bprime[i,j]=

Oops

ther is lot of problmes in this code ,
"" exit status 1
expected primary-expression before '=' token ""

for ( i = 1; i <= n ; i++){
            for (j = 1; j <= n ; j++){
              switch (bprime[i,j]) {

false insalisation !! ?

Please, just cut and paste the error messages, don't try to paraphrase them

Hi.
X is not a array,
therefore x [i] does not exist.

x[i] = r * (x[i - 1] * (1 - x[i - 1]));

Here iswrong too: int Matrix = 'A';
'A' is char, not int.

here too : #define i

RV mineirin

1 Like

it is a long error :pensive:

arduino:23:13: error: expected primary-expression before '=' token
     for ( i = 2; i <= (n*n/8) ; i++) {
             ^
arduino:23:20: error: expected primary-expression before '<=' token
     for ( i = 2; i <= (n*n/8) ; i++) {
                    ^~
arduino:23:36: error: expected primary-expression before ')' token
     for ( i = 2; i <= (n*n/8) ; i++) {
                                    ^
arduino:25:13: error: expected primary-expression before ']' token
          x[i] = r * (x[i-1]*(1 - x[i-1]));
             ^
arduino:25:27: error: invalid types 'float[int]' for array subscript
          x[i] = r * (x[i-1]*(1 - x[i-1]));
                           ^
arduino:25:39: error: invalid types 'float[int]' for array subscript
          x[i] = r * (x[i-1]*(1 - x[i-1]));
                                       ^
arduino:31:22: error: expected unqualified-id before '=' token
               int  i =u-1 ;
                      ^
arduino:38:28: error: invalid types 'int[int]' for array subscript
                     b[8*i+k]=1 ;
                            ^
arduino:43:26: error: invalid types 'int[int]' for array subscript
                   b[8*i+k]= 0;
                          ^
arduino:47:29: error: invalid types 'int[int]' for array subscript
                       b[1,tt]=1;
                             ^
arduino:51:19: error: expected primary-expression before '=' token
           for ( i = 1; i <= n ; i++){
                   ^
arduino:51:26: error: expected primary-expression before '<=' token
           for ( i = 1; i <= n ; i++){
                          ^~
arduino:51:36: error: expected primary-expression before ')' token
           for ( i = 1; i <= n ; i++){
                                    ^
arduino:52:21: error: expected primary-expression before '=' token
             for ( j = 1; j <= n ; j++){
                     ^
arduino:52:28: error: expected primary-expression before '<=' token
             for ( j = 1; j <= n ; j++){
                            ^~
arduino:52:38: error: expected primary-expression before ')' token
             for ( j = 1; j <= n ; j++){
                                      ^
arduino:53:24: error: invalid type argument of unary '*' (have 'int')
              int l = i*n+j;
                        ^
arduino:53:27: error: expected primary-expression before ';' token
              int l = i*n+j;
                           ^
arduino:54:14: error: 'bprime' was not declared in this scope
              bprime[i,j]= 2*b[l]+b[l+1];
              ^~~~~~
C:\Users\Mohammed\Desktop\sketch_may15a\arduino\arduino.ino:54:14: note: suggested alternative: 'fwrite'
              bprime[i,j]= 2*b[l]+b[l+1];
              ^~~~~~
              fwrite
arduino:54:22: error: expected primary-expression before ',' token
              bprime[i,j]= 2*b[l]+b[l+1];
                      ^
arduino:54:24: error: expected primary-expression before ']' token
              bprime[i,j]= 2*b[l]+b[l+1];
                        ^
arduino:54:32: error: invalid types 'int[int]' for array subscript
              bprime[i,j]= 2*b[l]+b[l+1];
                                ^
arduino:54:39: error: invalid types 'int[int]' for array subscript
              bprime[i,j]= 2*b[l]+b[l+1];
                                       ^
arduino:58:18: error: expected primary-expression before '=' token
          for ( i = 1; i <= n ; i++){
                  ^
arduino:58:25: error: expected primary-expression before '<=' token
          for ( i = 1; i <= n ; i++){
                         ^~
arduino:58:35: error: expected primary-expression before ')' token
          for ( i = 1; i <= n ; i++){
                                   ^
arduino:59:20: error: expected primary-expression before '=' token
             for (j = 1; j <= n ; j++){
                    ^
arduino:59:27: error: expected primary-expression before '<=' token
             for (j = 1; j <= n ; j++){
                           ^~
arduino:59:37: error: expected primary-expression before ')' token
             for (j = 1; j <= n ; j++){
                                     ^
arduino:60:23: error: 'bprime' was not declared in this scope
               switch (bprime[i,j]) {
                       ^~~~~~
C:\Users\Mohammed\Desktop\sketch_may15a\arduino\arduino.ino:60:23: note: suggested alternative: 'fwrite'
               switch (bprime[i,j]) {
                       ^~~~~~
                       fwrite
arduino:60:31: error: expected primary-expression before ',' token
               switch (bprime[i,j]) {
                               ^
arduino:60:33: error: expected primary-expression before ']' token
               switch (bprime[i,j]) {
                                 ^
arduino:62:25: error: 'fprime' was not declared in this scope
                         fprime[i,j]=f^k1;
                         ^~~~~~
C:\Users\Mohammed\Desktop\sketch_may15a\arduino\arduino.ino:62:25: note: suggested alternative: 'fwrite'
                         fprime[i,j]=f^k1;
                         ^~~~~~
                         fwrite
arduino:62:33: error: expected primary-expression before ',' token
                         fprime[i,j]=f^k1;
                                 ^
arduino:62:35: error: expected primary-expression before ']' token
                         fprime[i,j]=f^k1;
                                   ^
arduino:62:38: error: invalid operands of types 'double' and 'int' to binary 'operator^'
                         fprime[i,j]=f^k1;
arduino:65:33: error: expected primary-expression before ',' token
                         fprime[i,j]=f^(~k1);
                                 ^
arduino:65:35: error: expected primary-expression before ']' token
                         fprime[i,j]=f^(~k1);
                                   ^
arduino:65:38: error: invalid operands of types 'double' and 'int' to binary 'operator^'
                         fprime[i,j]=f^(~k1);
                                     ~^~~~~~
arduino:68:33: error: expected primary-expression before ',' token
                         fprime[i,j]=f^k2;
                                 ^
arduino:68:35: error: expected primary-expression before ']' token
                         fprime[i,j]=f^k2;
                                   ^
arduino:68:38: error: invalid operands of types 'double' and 'int' to binary 'operator^'
                         fprime[i,j]=f^k2;
arduino:71:32: error: expected primary-expression before ',' token
                        fprime[i,j]=f^(~k2);
                                ^
arduino:71:34: error: expected primary-expression before ']' token
                        fprime[i,j]=f^(~k2);
                                  ^
arduino:71:37: error: invalid operands of types 'double' and 'int' to binary 'operator^'
                        fprime[i,j]=f^(~k2);
                                    ~^~~~~~
exit status 1
expected primary-expression before '=' token

You haven't given i or j a datatype.

Did you you write this code?

delete these and define i, j as int

one of many errors.

it is a code matlab and i try to translate to arduino code so i wrote this cuz i don't have experience in arduino

thnx i fixe this but i still have problmes

Ok there are several ones like this.
RV mineirin

1 Like

thank you , I try to do this but still a lot of problems

arduino:23:18: error: expected unqualified-id before '=' token
     for (  int i = 2; i <= (n*n/8) ; i++) {
                  ^
arduino:23:18: error: expected ';' before '=' token
arduino:23:18: error: expected primary-expression before '=' token
arduino:23:25: error: expected primary-expression before '<=' token
     for (  int i = 2; i <= (n*n/8) ; i++) {
                         ^~
arduino:23:36: error: expected ')' before ';' token
     for (  int i = 2; i <= (n*n/8) ; i++) {
                                    ^
arduino:23:41: error: expected primary-expression before ')' token
     for (  int i = 2; i <= (n*n/8) ; i++) {
                                         ^
arduino:31:22: error: expected unqualified-id before '=' token
               int  i =u-1 ;
                      ^
arduino:38:28: error: invalid types 'int[int]' for array subscript
                     b[8*i+k]=1 ;
                            ^
arduino:43:26: error: invalid types 'int[int]' for array subscript
                   b[8*i+k]= 0;
                          ^
arduino:47:29: error: invalid types 'int[int]' for array subscript
                       b[1,tt]=1;
                             ^
arduino:51:24: error: expected unqualified-id before '=' token
           for (  int i = 1; i <= n ; i++){
                        ^
arduino:51:24: error: expected ';' before '=' token
arduino:51:24: error: expected primary-expression before '=' token
arduino:51:31: error: expected primary-expression before '<=' token
           for (  int i = 1; i <= n ; i++){
                               ^~
arduino:51:36: error: expected ')' before ';' token
           for (  int i = 1; i <= n ; i++){
                                    ^
arduino:51:41: error: expected primary-expression before ')' token
           for (  int i = 1; i <= n ; i++){
                                         ^
arduino:58:21: error: expected unqualified-id before '=' token
          for (int i = 1 ; i <= n ; i++){
                     ^
arduino:58:21: error: expected ';' before '=' token
arduino:58:21: error: expected primary-expression before '=' token
arduino:58:29: error: expected primary-expression before '<=' token
          for (int i = 1 ; i <= n ; i++){
                             ^~
arduino:58:34: error: expected ')' before ';' token
          for (int i = 1 ; i <= n ; i++){
                                  ^
arduino:58:39: error: expected primary-expression before ')' token
          for (int i = 1 ; i <= n ; i++){
                                       ^
exit status 1
expected unqualified-id before '=' token

did you removed the #define i?

Please, when you make a change, post the modified code and the error messages.

Your array indices need a lot of attention.

yes I do . and have those problems now

arduino:23:13: error: invalid types 'float[int]' for array subscript
          x[i] = r * (x[i-1]*(1 - x[i-1]));
             ^
arduino:23:27: error: invalid types 'float[int]' for array subscript
          x[i] = r * (x[i-1]*(1 - x[i-1]));
                           ^
arduino:23:39: error: invalid types 'float[int]' for array subscript
          x[i] = r * (x[i-1]*(1 - x[i-1]));
                                       ^
arduino:36:28: error: invalid types 'int[int]' for array subscript
                     b[8*i+k]=1 ;
                            ^
arduino:41:26: error: invalid types 'int[int]' for array subscript
                   b[8*i+k]= 0;
                          ^
arduino:45:29: error: invalid types 'int[int]' for array subscript
                       b[1,tt]=1;
                             ^
arduino:52:14: error: 'bprime' was not declared in this scope
              bprime[i,j]= 2*b[l]+b[l+1];
              ^~~~~~
C:\Users\Mohammed\Desktop\sketch_may15a\arduino\arduino.ino:52:14: note: suggested alternative: 'fwrite'
              bprime[i,j]= 2*b[l]+b[l+1];
              ^~~~~~
              fwrite
arduino:52:32: error: invalid types 'int[int]' for array subscript
              bprime[i,j]= 2*b[l]+b[l+1];
                                ^
arduino:52:39: error: invalid types 'int[int]' for array subscript
              bprime[i,j]= 2*b[l]+b[l+1];
                                       ^
arduino:58:23: error: 'bprime' was not declared in this scope
               switch (bprime[i,j]) {
                       ^~~~~~
C:\Users\Mohammed\Desktop\sketch_may15a\arduino\arduino.ino:58:23: note: suggested alternative: 'fwrite'
               switch (bprime[i,j]) {
                       ^~~~~~
                       fwrite
arduino:60:25: error: 'fprime' was not declared in this scope
                         fprime[i,j]=f^k1;
                         ^~~~~~
C:\Users\Mohammed\Desktop\sketch_may15a\arduino\arduino.ino:60:25: note: suggested alternative: 'fwrite'
                         fprime[i,j]=f^k1;
                         ^~~~~~
                         fwrite
arduino:60:38: error: invalid operands of types 'double' and 'int' to binary 'operator^'
                         fprime[i,j]=f^k1;
arduino:63:38: error: invalid operands of types 'double' and 'int' to binary 'operator^'
                         fprime[i,j]=f^(~k1);
                                     ~^~~~~~
arduino:66:38: error: invalid operands of types 'double' and 'int' to binary 'operator^'
                         fprime[i,j]=f^k2;
arduino:69:37: error: invalid operands of types 'double' and 'int' to binary 'operator^'
                        fprime[i,j]=f^(~k2);
                                    ~^~~~~~
exit status 1
invalid types 'float[int]' for array subscript

okey I sorry .. so this is the code


#define k1 23    // key 1
#define k2 84    // key 2
#define r 4
float x= 0.78 ;
int n=16 ;
char Matrix = 'A';
double f = Matrix ;    
int  tt;
int  b;                    
                              
void setup() {


}

void loop() {
    for (  int i = 2; i <= (n*n/8) ; i++) {
     
         x[i] = r * (x[i-1]*(1 - x[i-1]));

            }
            //partie de binairisation 
            for (int u = 1; u <= (n*n/8) ; u++){
              int  a=(u);
              int  i =u-1 ;
                for (int k = 1; k <= 16 ; k++){
                     int z = pow(2,k);
                     int a ;
                
                    if (a>=1/z){
                    a=(a-1)/z;
                    b[8*i+k]=1 ;
                              }
                
                    else  {
                       a=a;
                  b[8*i+k]= 0;
                   
                      }
                      tt=16*u+1;
                      b[1,tt]=1;  
                }
            }
         //    partie de cryptage  
          for (  int i = 1; i <= n ; i++){
            for (int j = 1; j <= n ; j++){
             int l = i*n+j;
             bprime[i,j]= 2*b[l]+b[l+1];
            }
            }
         // cryptage   
         for (int i = 1 ; i <= n ; i++){
            for ( int j = 1 ; j <= n ; j++){
              switch (bprime[i,j]) {
                  case 1:
                        fprime[i,j]=f^k1;
                     break;
                  case 2:
                        fprime[i,j]=f^(~k1);
                      break;
                  case 3:
                        fprime[i,j]=f^k2;
                       break;
                default:
                       fprime[i,j]=f^(~k2);
                   break;
                  }   
              }
            }
}

and this is the errors

arduino:23:13: error: invalid types 'float[int]' for array subscript
          x[i] = r * (x[i-1]*(1 - x[i-1]));
             ^
arduino:23:27: error: invalid types 'float[int]' for array subscript
          x[i] = r * (x[i-1]*(1 - x[i-1]));
                           ^
arduino:23:39: error: invalid types 'float[int]' for array subscript
          x[i] = r * (x[i-1]*(1 - x[i-1]));
                                       ^
arduino:36:28: error: invalid types 'int[int]' for array subscript
                     b[8*i+k]=1 ;
                            ^
arduino:41:26: error: invalid types 'int[int]' for array subscript
                   b[8*i+k]= 0;
                          ^
arduino:45:29: error: invalid types 'int[int]' for array subscript
                       b[1,tt]=1;
                             ^
arduino:52:14: error: 'bprime' was not declared in this scope
              bprime[i,j]= 2*b[l]+b[l+1];
              ^~~~~~
C:\Users\Mohammed\Desktop\sketch_may15a\arduino\arduino.ino:52:14: note: suggested alternative: 'fwrite'
              bprime[i,j]= 2*b[l]+b[l+1];
              ^~~~~~
              fwrite
arduino:52:32: error: invalid types 'int[int]' for array subscript
              bprime[i,j]= 2*b[l]+b[l+1];
                                ^
arduino:52:39: error: invalid types 'int[int]' for array subscript
              bprime[i,j]= 2*b[l]+b[l+1];
                                       ^
arduino:58:23: error: 'bprime' was not declared in this scope
               switch (bprime[i,j]) {
                       ^~~~~~
C:\Users\Mohammed\Desktop\sketch_may15a\arduino\arduino.ino:58:23: note: suggested alternative: 'fwrite'
               switch (bprime[i,j]) {
                       ^~~~~~
                       fwrite
arduino:60:25: error: 'fprime' was not declared in this scope
                         fprime[i,j]=f^k1;
                         ^~~~~~
C:\Users\Mohammed\Desktop\sketch_may15a\arduino\arduino.ino:60:25: note: suggested alternative: 'fwrite'
                         fprime[i,j]=f^k1;
                         ^~~~~~
                         fwrite
arduino:60:38: error: invalid operands of types 'double' and 'int' to binary 'operator^'
                         fprime[i,j]=f^k1;
arduino:63:38: error: invalid operands of types 'double' and 'int' to binary 'operator^'
                         fprime[i,j]=f^(~k1);
                                     ~^~~~~~
arduino:66:38: error: invalid operands of types 'double' and 'int' to binary 'operator^'
                         fprime[i,j]=f^k2;
arduino:69:37: error: invalid operands of types 'double' and 'int' to binary 'operator^'
                        fprime[i,j]=f^(~k2);
                                    ~^~~~~~
exit status 1
invalid types 'float[int]' for array subscript

where is "x" defined as an array?

Hi.
"commands" like this "bprime [i, j]" in "C" are used to address arrays, but I think that in its algorithm it has another meaning and is confusing with the language.

What´s meaning of this , " x[i], bprime [i, j] " for you?
RV mineirin