Solved

Asterik character in stream functions

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

This tutorial is posted by Aaron Wojnowski, administrator at SDKExpert.net.  To view more iPhone tutorials, visit www.sdkexpert.net. This is a very simple tutorial on finding the user's current location easily. In this tutorial, you will learn ho…
Summary: This tutorial covers some basics of pointer, pointer arithmetic and function pointer. What is a pointer: A pointer is a variable which holds an address. This address might be address of another variable/address of devices/address of fu…
The goal of this video is to provide viewers with basic examples to understand and use structures in the C programming language.
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use nested-loops in the C programming language.

705 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now