I have to following code:
// Write screen n = sprintf( screen_msg, " TV: %#4.1f FV: %#4.1f CV: %#4.1f SV: %#4.1f\r\n", ad_value[2], ad_value[1], ad_value[0], ad_value[3] ); n += sprintf( screen_msg + n, " TI: %#4.1f AT: %#4.1f CT: %#4.1f ST: %#4.1f\r\n", ad_value[4], ad_value[5], ad_value[7], ad_value[6] ); n += sprintf( screen_msg + n, "\r\n" ); n += sprintf( screen_msg + n, "ENGINE CHARGE CLK EN DIS" ); write_0( screen_msg );
When the string is printed to my LCD CV, SV, and ST are always zero, regardless of the value in the ad_value array. If I print just those values in the same routine they appear as they should. When I debug the program the entire string appears as it should. My screen_msg buffer is 256 characters and the entire string in only 170.
I have looked over the code a dozen times and can't figure out what's going on. Can anyone see something that I may be missing?
Thanks, Paul
Mike,
Yes, you are the first ;-) - I was posting this particular message w/o resfreshing the list. I would say, many stuff in this world depends on habits and style so I should not be so categorical saying "it is totally wrong", what I meant ;-) is actually, "I would not recommend this approach" - because in my opinion constructions like n+= sprintf(buffer + n, ...) are prone to be messed-up with, easily. That is the reason when you look at glance (typically, at glance ;-) ) at somebody's code you might not really dig deep into it but the very first suspicion might be brought up due to the syntax only. And only after that if you have deeper look at the code (as it happened here with me), yes, you can say: "well, it works..." but still simpler syntax arouses more confidence. Anyway, this is just my vision..
Regards, Nikolay.
Nikolay,
After reading your first post again I understood what you were trying to say. I agree with you in that the structure as written is prone error. With your help and Mike's help I fixed the problem.
Thanks for all your help.
Paul