Array aren't initialized.

Sorry if I posted too much earlier.

I am going to make the receiver, and so it needs to print out the received char as an array, so I assign it the value “i”, and through each loop “i” will increase by 1.

So, if the character sent are 12345#, it will write “1” for the index 0, “2” for the index 1, and so on, until it reaches “#”. It said it may not be initialized. Please, help me! Thank You!

Receiver:

int i, good, k;
byte data_in;
char array[] ="";
void setup(){
  attachInterrupt(1,data_incoming,RISING);
  pinMode(3, INPUT);
  pinMode(13, OUTPUT);
}//setup

void loop(){
  
  
}//loop






void data_incoming(){
    
    
    for(i=0; i<100; i++){
      delayMicroseconds(20);
      good=1;
      if(digitalRead(3)==LOW){
      good=0;
      i=100;
      }
    }//for
      
    if(good==1){
    detachInterrupt(1);
    while(1){
      if(digitalRead(3)==LOW){
        delayMicroseconds(750);

        for(i=0; i<8; i++){
          if(digitalRead(3)==HIGH)
          bitWrite(data_in, i, 1);
          else
          bitWrite(data_in, i, 0);
          delayMicroseconds(1000);
        }//for
        int i =0;
        if(data_in=='#')
       char array[i] = "";
        else
        char array[i] = char(data_in);
        i++;

       break;//secondtwhile
      }//low kickoff
      
    }//second while
    
    }//good check

  attachInterrupt(1,data_incoming,RISING);
  
  
  
}//routine

Error Message:

StringReceiver:47: error: initializer-string for array of chars is too long [-fpermissive]
StringReceiver:49: error: array must be initialized with a brace-enclosed initializer
initializer-string for array of chars is too long [-fpermissive]

Transmitter Code (if you need to refer to):

int i, good, k;
byte data_in;
char array[] ="";
void setup(){
  attachInterrupt(1,data_incoming,RISING);
  pinMode(3, INPUT);
  pinMode(13, OUTPUT);
}//setup

void loop(){
  
  
}//loop






void data_incoming(){
    
    
    for(i=0; i<100; i++){
      delayMicroseconds(20);
      good=1;
      if(digitalRead(3)==LOW){
      good=0;
      i=100;
      }
    }//for
      
    if(good==1){
    detachInterrupt(1);
    while(1){
      if(digitalRead(3)==LOW){
        delayMicroseconds(750);

        for(i=0; i<8; i++){
          if(digitalRead(3)==HIGH)
          bitWrite(data_in, i, 1);
          else
          bitWrite(data_in, i, 0);
          delayMicroseconds(1000);
        }//for
        int i =0;
        if(data_in=='#')
       char array[i] = "";
        else
        char array[i] = char(data_in);
        i++;

       break;//secondtwhile
      }//low kickoff
      
    }//second while
    
    }//good check

  attachInterrupt(1,data_incoming,RISING);
  
  
  
}//routine

These codes are based upon RF Links Tutorial - Cheap and Easy Wireless Arduino! - YouTube.
Original Transmitter Code: http://www.kevindarrah.com/download/arduino_code/transmit3_31.ino
Original Receiver Code: http://www.kevindarrah.com/download/arduino_code/receive3_31.ino

  1. Re-read the documents on array.
char array[] ="";

Create an array of length 1
2. Scope - look it up

char array[] ="";

is not the same array (even if it has the (same stupid) name as

        char array[i] = char(data_in);
  1. Never use delay()

  2. You should not be using interrupts

  3. If you do use interrupts NEVER NEVER use detachInterrupt()

Mark

I still don't under stand why char array is not the same as char array[].

Naming something array does not make it an array, the square brackets do.

int value    = 10;
int values[] = { 1, 2, 3, 4 };
char array[] = "";

creates an array with a size of one character ((as explained above) that contains the terminating null character and therefor is an empty character string).
It's the same as

char array[] = {'\0'};

If you know the maximum size that you will receive, you declare an character array as below.

char array[6];

which will create an character array with space for 5 characters plus a terminating null character.

char array[i] = "";

Not sure what you try to achieve; probably assign an empty string to an element of an character array.

But you are declaring an character array with size i and assigning a character string to that. Take the 'char' out and you will be assigning the empty string to the variable array that you declared earlier (near the top of the code). This will still result in an error message because you are assigning a character string to a char.

invalid conversion from 'const char*' to 'char' [-fpermissive]

Assuming that you want to terminate the character string

array[i] = '\0';

Next problem

char array[i] = char(data_in);

Again, you're declaring an array so you take the 'char' out if you want to refer to the earlier declared variable called 'array'.

Not quite sure what char(data_in) does. It does compile, but might not do what you want. Maybe you want to use a cast to convert the byte to a char.

array[i] = (char)data_in;

And because your initial array declaration only contains space for one char, your code will probably crash until you fixed it as suggested.

char array [i]

says "Make an array of chars with i elements".

Probably not what you want to do.