I think I'm on the right track now thanks to you guys.
One more question; If there is only one statement to execute in the for loop, are the braces around that statement still required?
David_AVD,
c4757p already pointed out that you don't really need the { } except for multiple statements. An additional useful technique is comma which continues the calculation statement. When comma is used, the last statement has the final value and that is used.
ii = 1, 2, 3, 4 ; // ii is assigned 4, the last evaluation done
original:
while (*buffer) {
lcd_char(*buffer);
buffer++;
}another version with comma to make that one statement:
while (*buffer) lcd_char(*buffer), buffer++;another version with for ( ; ; )
for ( ;*buffer; lcd_char(*buffer), ++buffer ) ;Explaination
for ( ; // this first semicolon with stuff between ( ; means no initialization needed
for ( ; *buffer; // between the first and second semicolon is the condition to
// remain looping, so here is checking to see if current buffer char is
// not null before continue loop
for ( ;*buffer; lcd_char(*buffer), ++buffer ) // after the last semicolon, there is the end of a loop closing statement
// before end of the loop, do the lcd_char. Since it is a comma, it continue
// the calculation and do the buffer pointer increment to point at the next char
for ( ;*buffer; lcd_char(*buffer), ++buffer ) ; // the semicolon after the ) saids I have an empty statement
// there is nothing to left to do
Now one with size limit:
int ii,newSize;
for (ii=0, newSize=100 ; *buffer & ii<newSize; ii++, lcd_char(*buffer), ++buffer);I leave it for you to figure out the intialization, the continue-loop checking, and the loop end check.
Good luck with your C learning. It will be a fun ride.
By the way, note this joke, it highlights some C programming facts:
When a C programmer brought a dozen eggs, how many eggs did he just buy?
The answer is 11.
0 , 1, 2, 3, 4, 5, 6, 7, 8, 9, 10,11
Only 11. C programmer always start counting with zero.
Rick