I am converting some code from C into delphi pascal and have come to a brick wall. As my understanding of C is quite limited i am unsure of what '%*.*ld' is doing or how to do the same thing in Dephi. The full line is a bit long to put in here, but this is a similar one i am having trouble with:

MGRS_String := sprintf(MGRS+MGRS_String,'%2.2ld',Zone)

where zone is an integer. Any help would be appreciated
-J

%ld is a long integer. You can add a field width that specifies the minimum number of characters to print. So %5ld will pad numbers with fewer than five digits using spaces. You can add a precision using a period and another number that specifies the minimum number of digits in the number. So if you print the value 1 with %5.3ld, you'll get 001 padded with two spaces because the number is now 3 characters in length.

%2.2ld is effectively equivalent to %02ld because the field width negates the precision and the precision negates the field width. So if you print 1, you'd get 01 with no padding.

It's a placeholder for an argument that you supply later on:

printf("%*d\n", w, x);

Instead of specifying the width explicitly, printf takes it from the matching argument, which is w in this case.

I had to use this function a few day ago. It works pretty slick to create a string from int, long an so on.

It's a placeholder for an argument that you supply later on:

printf("%*d\n", w, x);

Instead of specifying the width explicitly, printf takes it from the matching argument, which is w in this case.

This article has been dead for over six months. Start a new discussion instead.