Go Down

Topic: Running Text on a 16x2 LCD (Read 33261 times) previous topic - next topic


Feb 04, 2011, 06:16 am Last Edit: Feb 04, 2011, 06:19 am by davekw7x Reason: 1

...buffer[1] = '\0';

The loop in sendmsg (from your code) uses the zero byte to know when it has reached the end of the "string."  That's the way that "normal" C library functions handle these things, and it is a convention followed by C programmers everywhere (well, almost everywhere).

Here's the loop:

Code: [Select]

   while (*str) {

That means that the pointer is incremented each time through the loop.  When the pointer reaches the address of the zero byte, the "while" condition fails, and that's the end of the road.  The calling function puts a single character at the beginning of the buffer, followed by a zero byte, every time my program called the function.  That's just an example.  You could put any kind of C-style "string" in the buffer (always terminated by a zero byte).





Thanks for your explanation. I understood.

My misunderstanding came from the way I wanted to implement the storage of chars. In the first go I wanted /want to use a two dimensional array (matrix) (something like char lines [16] [10]) so that I am able to retrieve a longer text on the display via the buttons on the LCD shield. The control of the matrix should be done by loops. I was not aware that a transition from "normal" array to string was triggered.

Now I see that it is easier to go with strings incl. termination. Oh dear, perhaps I should have stayed with things I know how to handle.

Again thanks for your time and engagement.

Go Up