Some basic problem with saving array

I have this :

   char input[100]={0};
  //.....

   void loop() {
 
          int bytes=0;
           while (Serial.available() > 0) 
           {
                input[bytes]=Serial.read();
                input[bytes+1]= '\0';
                 
                bytes++;
                  
           }
           Serial.println(input);

Sometimes when I type to the terminal A5 it prints A5, but sometimes only 5. Somehow this code is not reliable and I am searching whats wrong ?

You assume serial data arrives in nice neat packages. It does not. It arrives one byte at a time with a significant elapsed time between bytes.

I don't assume anything. Why is it matter, at the end of the day, input array must have the right word I type in (at least from a certain point in time).

Whats wrong with the code that it prints for input "A5" , this:

5
5
5
5
5

5
5
5
5

5
5
5

By declaring the variable bytes inside loop(), it comes into existence each time loop() runs, and is initialised to 0 each time.

If you want the variable to keep its value between each run of loop(), make it static:

static int bytes = 0;

Also, you probably should only print the input string when it changes (i.e. when you add a new character to it). So try moving the print statement inside the while loop.

So if I take the bytes out, how do I know when to initialise it again to zero ? If you can't really know when you got your data ? Do I need to set an end sign inside my data protocol ?

(it used to work with a 16Mhz just like that, but now with a 48Mhz I guess its faster)

What you have posted should work, with the caveat that you may get spurious newlines depending on how the incoming serial content is chunked. Realistically, if you are using the serial monitor then you will almost certainly get one chunk per line of input and I would expect his to work just fine.

So perhaps you should post your entire sketch like the sticky post says to. See snippets-r-us.com. See if you can produce a minimal sketch that reproduces the problem.

So if I take the bytes out, how do I know when to initialise it again to zero ?

When you have received a complete packet.

If you can't really know when you got your data ?

How do you know when to quit reading a word in this reply? To quit reading a sentence?

That's what delimiters are for. When you receive the correct one, that marks the end of a packet. Process the packet, and set bytes back to 0.