serial communication code working only once!

Hi,
Experimenting with ser comm I found yet another interesting issue I can't explain. Please look at this code:

char a;
char m[10];
int i = 0;

void setup()
{
  Serial.begin(9600);
  Serial.flush();
}

void loop()
{
  while(Serial.available()>0 && a != '@')  
  {
     a = Serial.read();
     m[i++] = a;
     if(i>=10 || a=='@')
     {
       i = 0;
       Serial.println(m); 
     }
  }
}

This fairly simple code has a bug I can't figure out: when I run it, and say I enter kkk@ it prints it as expected. After this it stops working and if I enter, say, ttt@ it does nothing! Any other attempt to make it println something fails!

Do you see the problem there please?

The problem is that once variable a is equal to '@' then there is nothing to make it not equal to it and so it never reads again, exactly like you have coded.
So it is doing exactly what the code says it should.
maybe after the print statement put an :-
a = 0;

Thanks! It is now ok :smiley: