What does "%.*s" do in a sprintf statement

I have to convert some already present C files (not created by me) to Java files.

But there is a statement of type

[code]
sprintf(char *,"%.*s",int,char *);
[/code]
e.g.
[code]
sprintf(buffer,"%.*s",x,start);
[/code]

Can anyone exactly tell me what this statement is doning??

Its urgent.

Comments

  • : I have to convert some already present C files (not created by me) to Java files.
    :
    : But there is a statement of type
    :
    : [code]
    : sprintf(char *,"%.*s",int,char *);
    : [/code]
    : e.g.
    : [code]
    : sprintf(buffer,"%.*s",x,start);
    : [/code]
    :
    : Can anyone exactly tell me what this statement is doning??
    :
    : Its urgent.
    :

    sprintf() is used to make what's called formatted type conversions it and its counter part sscanf() simply converts string of information to a proper varible and viceversa. eg. you can take a not so useful string like "10" and convert it to a nice integer like 10.

    this is probably a whole lot more helpful than my entry: http://www.opengroup.org/onlinepubs/000095399/functions/sprintf.html

  • : I have to convert some already present C files (not created by me) to Java files.
    :
    : But there is a statement of type
    :
    : [code]
    : sprintf(char *,"%.*s",int,char *);
    : [/code]
    : e.g.
    : [code]
    : sprintf(buffer,"%.*s",x,start);
    : [/code]
    :
    : Can anyone exactly tell me what this statement is doning??
    :
    : Its urgent.
    :

    [blue]In this case, the [italic]*[/italic] will be replaced by the value given in the variable [italic]x[/italic]. For example, if [italic]x[/italic] was 10 then the effect would be as if you had called the function as follows:
    [code]sprintf(buffer,"%.10s",start);[/code]
    This of course would have the effect of printing/copying up to the first 10 characters of the character array/string in the variable [italic]start[/italic] (or fewer characters if [italic]start[/italic] does not contain that many characters) into the array [italic]buffer[/italic].[/blue]

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories