creating char array problem

am trying to create an array of char but i think i have failed to using indexing properly to read characters in some sequence.

char incomingbyte[37]; // for incoming serial data
int val =0;
int i;

void setup() {
Serial.begin(9600); // opens serial port, sets data rate to 9600 bps
}

void loop() {

// send data only when you receive data:
if (Serial.available() > 0) {
i=0;
while(i<37){
if (Serial.available()>0){
val=Serial.read();
if (i==37){
break;
}
incomingbyte*=val;*

  • i++;*
  • }*
  • }*
  • // read the incoming byte:*
  • // incomingByte = Serial.read();*
  • // say what you got:*
  • Serial.print("I received: ");*
  • Serial.println(incomingbyte);*
  • }*
    }

//please spot any problems in this sketch

The code does something. You haven't explained what it does.

You want it to do something. You haven't explained what that is.

It's hard to get from here to there without knowing where here or there is.

am trying to create an array of char but i think i have failed to using indexing properly to read characters in some sequence.

You have not failed to use indexing properly, you have failed to use indexing at all.incomingbyte=val;The code you posted does not compile but the error that it gives is a clue as to what is wrong. Once you have sorted out the problem with indexing the array you can tackle the other problems like what happens if more or less than 37 bytes are received, the fact that the array needs to be terminated before it can be treated as a string and printed and its size if a terminator is to be added.

Naming an array of chars incomingbyte could cause confusion at some point too. If you were to put your code in code tags when posting it here then it would be easier to read.

Likely, the OP did use indexing correctly, but the forum software interpreted [i] as a request for italics.

Post your code again using code tags - # button above.

You'll need to null terminate your string before you print it too.

Good thought and an excellent endorsement as to why code tags should be used.