Solved

Asterik character in stream functions

Posted on 2006-11-10
1
206 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

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
voltage to force translation ? 8 99
How do I install gcc 4.8.4 on a Linux Ubuntu 14.04 machine? 5 1,933
How to jump to matching brace in eclipse editor ? 1 319
delete-remove 14 97
Have you thought about creating an iPhone application (app), but didn't even know where to get started? Here's how: ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ Important pre-programming comments: I’ve never tri…
Preface I don't like visual development tools that are supposed to write a program for me. Even if it is Xcode and I can use Interface Builder. Yes, it is a perfect tool and has helped me a lot, mainly, in the beginning, when my programs were small…
The goal of this video is to provide viewers with basic examples to understand and use pointers in the C programming language.
The goal of this video is to provide viewers with basic examples to understand and use switch statements in the C programming language.

808 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