Re: Pro*C examples: printf question

From: Steve Mitchell <steve_at_mitchells.demon.co.uk>
Date: 1997/05/15
Message-ID: <337B7914.57BB_at_mitchells.demon.co.uk>#1/1


A format specification for the printf function has the following form

  %[flags] [width] [.precision] [{h | l | L}]type.

[ ] indicates an option.

The format specification %.*s has no flag or width arguments.

The '.*' is the precision argument and for strings represents the maximum number of characters to be output for the field.

When the precision field is a *, an int argument that precedes the string argument in the argument list supplies the precision value.

For example.

   printf("String is %.3s","Hello world");

    >String is Hel

   printf("String is %.*s",8,"Hello world");

    >String is Hello Wo

-- 
Cornishmen do it dreckly

Chuck Hamilton wrote:

>
> Some of Oracle's Pro*C demo programs, such as sqlvcp.pc, contain a
> printf flag that I've never seen before. In the following statment:
>
> printf("%.*s\n", msg_len, err_msg);
>
> what is the '.' flag for? It's not documented in any of my C manuals.
> --
> Chuck Hamilton
> chuckh_at_dvol.com
>
> If at first you don't succeed, skydiving isn't for you.
Received on Thu May 15 1997 - 00:00:00 CEST

Original text of this message