I have a buffer which I receive through a serial port. When I receive a certain character, I know a full line has arrived, and I want to print it with printf
method. But each line has a different length value, and when I just go with:
printf("%s", buffer);
I'm printing the line plus additional chars belonging to the former line (if it was longer than the current one).
I read here that it is possible, at least in C++, to tell how much chars you want to read given a %s
, but it has no examples and I don't know how to do it in C. Any help?
I think I have three solutions:
- printing char by char with a
for
loop - using the termination character
- or using .*
QUESTION IS: Which one is faster? Because I'm working on a microchip PIC and I want it to happen as fast as possible