User`s guide
152
K
A
DAK
KwikNet Low Level Services
kn_fmt kn_fmt
Purpose Format a Text String
Used by
n Task o ISP o Timer Procedure n Restart Procedure n Exit Procedure
Setup Prototype is in file KN_API.H.
#include "KN_LIB.H"
int kn_fmt(char *bufp, const char *fmtp, ...);
Description Bufp is a pointer to storage for the formatted string.
Fmtp is a pointer to a format specification string similar to that expected
by the C library procedure printf(). Allowable format specifications
are summarized on the next page.
The format string is followed by zero or more parameters of types
specified by the format string.
Returns The formatted string is stored at *bufp and the length of that string is
returned. The length is a positive value. The string is terminated with a
'\0' character.
Example Other examples are provided in the descriptions of kn_cksum() and
kn_dprintf().
#include "kn_lib.h"
struct in_addr ipaddr; /* IPv4 address (numeric) */
char buf[80]; /* String buffer */
/* IP address = 192.168.5.21 */
ipaddr.s_addr = htonl(0xC0A80516);
if (kn_fmt(buf, "IP address 0x%08lX is '%03a'.\n",
ntohl(ipaddr.s_addr), ipaddr.s_addr) <= 0)
kn_dprintf(0, "Cannot convert IP address to string.\n");
else {
kn_dprintf(0, "%s", buf);
/* The previous message should read: */
/* "IP address 0xC0A80516 is '192.168.005.016'." */
}
See Also kn_dprintf()
...more