Hello, I am trying to create a string with a variable of type long, using sprintf.
char command [20]; long ofs = 363080; sprintf (command, "VAL=%d", ofs);
In C51, it is very important that you match the type of the actual parameters to the type of the format specifier; eg, %d is for a signed int; %u is for an unsigned int; %Ld is for a signed long; %Lu is for an unsigned long. I guess C166 is similar and you need to add the 'L' (not case-sensitive)
Thank you for your help! I only looked in a standard C-manual, where there's no such thing as an L. Of course I didn't think of checking the Keil manual first... sorry for that :) Holger
I only looked in a standard C-manual, where there's no such thing as an L Hmm... I think you need to throw that manual away and get a proper one! My ancient K&R (2nd Edition, 1988) says, "Between the % and the conversion character there may be ... an h if the integer is to be printed as a short, or l if as a long" It doesn't mention if the h and l are case-sensitive, but in C51 they certainly aren't (I prefer to use the uppercase L, as lowercase l looks too much like the digit 1 in many fonts) Note that K&R also says that printf, "will get confused, and you will get wrong answers, if there are not enough arguments or if they are the wrong type" (my emphasis)