Solved

Asterik character in stream functions

Posted on 2006-11-10
1
200 Views
Last Modified: 2010-04-15
What is the use of the asterik character in stream like functions, e.g. what does the following line of code actually do?

printf(" %-*s ", 50);

I saw this in some source code, but it just prints garbage characters.  I can tell the integer parameter refers to the field length it prints, but I can't tell what the "*s" refers to.


0
Comment
Question by:chsalvia
1 Comment
 
LVL 84

Accepted Solution

by:
ozo earned 50 total points
ID: 17920240
    A field width or precision, or both, may be indicated by an asterisk `*'
     or an asterisk followed by one or more decimal digits and a `$' instead
     of a digit string.  In this case, an int argument supplies the field
     width or precision.  A negative field width is treated as a left adjust-
     ment flag followed by a positive field width; a negative precision is
     treated as though it were missing.  If a single format directive mixes
     positional (nn$) and non-positional arguments, the results are undefined.
so it'd the same as
printf(" %-50s ");
which is missing a string argument
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Windows programmers of the C/C++ variety, how many of you realise that since Window 9x Microsoft has been lying to you about what constitutes Unicode (http://en.wikipedia.org/wiki/Unicode)? They will have you believe that Unicode requires you to use…
This is a short and sweet, but (hopefully) to the point article. There seems to be some fundamental misunderstanding about the function prototype for the "main" function in C and C++, more specifically what type this function should return. I see so…
The goal of this video is to provide viewers with basic examples to understand opening and writing to files in the C programming language.
The goal of this video is to provide viewers with basic examples to understand opening and reading files in the C programming language.

832 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question