01-23-2014
You give printf and scanf identical command strings, but %* means something very different to printf and scanf. It means "print this type to [format] characters wide" in printf, and "don't store this value" in scanf.
Also, you are giving printf all the same arguments too. scanf needs &i because scanf needs i's location, not its contents -- but printf needs its contents, not its location!
So, my best guess at what happened is that printf's %d prints part of a memory address (since you are on a 64-bit system, and %d expects a 32-bit integer). Next, %*s tries to get a width, and gets the other half of that memory address -- a very, very high number! So it prints several billion leading spaces before it actually gets to the string.
Last edited by Corona688; 01-23-2014 at 02:15 PM..
This User Gave Thanks to Corona688 For This Post:
10 More Discussions You Might Find Interesting
1. Programming
What is the output of the following program considering an x86 based parameter passing sequence where stack grows towards lower memory addresses and that arguments are evaluated from right to left:
int i=10;
int f1()
{
static int i = 15;
printf("f1:%d ", i);
return i--;
}
main()
{... (2 Replies)
Discussion started by: arunviswanath
2 Replies
2. Shell Programming and Scripting
How to print output in following format?
A..................ok
AA................ok
AAA..............ok
AAAAAA........ok
"ok" one under one (4 Replies)
Discussion started by: mirusnet
4 Replies
3. UNIX for Dummies Questions & Answers
Hi,
I have just completed my first script (:D) and now i just need to format it with printf.
This is what I have:
#!/bin/ksh
TOTB=0
TOTF=0
TOTI=0
HOST=`hostname`
echo " FSYSTEM BLKS FREE INUSE MOUNTEDON"
df -m | grep -v ":"|grep -v Free|grep -v "/proc"| while read FSYSTEM... (2 Replies)
Discussion started by: compan023
2 Replies
4. Shell Programming and Scripting
Target file contains short text (never more than 1 line) and filenames.
The format is, e.g.,:
TEXT1
filename1
TEXT2
TEXT3
filename3dddd
filename3dddd
TEXT4
filename4
TEXT5
filename5dddd
filename5dddd
filename5
where dddd is a random 4-digit whole number.
Desired output: (4 Replies)
Discussion started by: uiop44
4 Replies
5. UNIX for Dummies Questions & Answers
I have this command like that has %s in it, I know %s calls a column, but I am not sure I understand which column (I mean for my case I can check the input file, but I want to know how is this %s used, how comes tha same symbo; gives different columns in one command line:
{printf "grep %s... (22 Replies)
Discussion started by: cosmologist
22 Replies
6. Shell Programming and Scripting
I am having a major problem with printf, The more I pad it, the less I see :(
The problem is in the first function, report
Am I ruining output somewhere? I wont print out the names propely, it cuts them off or deletes them completely :(
#!/bin/bash
report()
{
printf "%-10s" STUD# ... (2 Replies)
Discussion started by: L0ckz0r
2 Replies
7. Programming
When I compile this i get the following error
"error: expected declaration specifiers or '...' before syslog"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#define __LIBRARY__
#include <linux/unistd.h>
/* define the system call, to override the library... (6 Replies)
Discussion started by: dragonpoint
6 Replies
8. Shell Programming and Scripting
Hi,
I a sequance number from 1-999 and i want asing the value like 001,002..999
Exp:
file_001
file_002
file_003...
file_999
How can i disaplay the sequnace number as mention above. (3 Replies)
Discussion started by: koti_rama
3 Replies
9. Shell Programming and Scripting
I have searched and the answers I have found thus far have led me to this point, so I feel I am just about there.
I am trying to convert a column of hexadecimal to decimal values so that I can filter out via grep just the data I want. I was able to pull my original 3 character hex value and... (10 Replies)
Discussion started by: PCGameGuy
10 Replies
10. Shell Programming and Scripting
hi all,
I had my script as
a=qw
b=rter
c=fdfd
curency=1000
printf"${curency} $a $b $c" > filename
can i have printf statement that can change the currency from 1000 to 1,000 like it should convert the number to currency format ..?(i.e for any number) (14 Replies)
Discussion started by: hemanthsaikumar
14 Replies
LEARN ABOUT ULTRIX
nl_fprintf
nl_printf(3int) nl_printf(3int)
Name
nl_printf, nl_fprintf, nl_sprintf - print formatted output
Syntax
#include <stdio.h>
int nl_printf ( format [, arg ] ... )
char *format;
int nl_fprintf ( stream, format [, arg ] ... )
FILE *stream;
char *format;
int nl_sprintf ( s, format [, arg ] ... )
char *s, format;
Description
The international functions and are identical to and have been superceded by the international functions and in a library. You should use
the and functions when you write new calls to print formatted output in an international program. For more information on these functions,
see the reference page.
You can continue to use existing calls to the or international functions. These functions remain available for compatibility with XPG-2
conformant software, but may not be supported in future releases of the ULTRIX system.
The and international functions are similar to the standard I/O function. (For more information about the standard I/O function, see the
reference page.) The difference is that the international functions allow you to use the I%digit$ conversion sequence in place of the %
character you use in the standard I/O functions. The digit is a decimal digit n from 1 to 9. The international functions apply conversions
to the n th argument in the argument list, rather than to the next unused argument.
You can use % conversion character in the international functions. However, you cannot mix the % conversion character with the %digit$
conversion sequence in a single call.
You can indicate a field width or precision by an asterisk (*), instead of a digit string, in strings containing the % conversion charac-
ter. If you use an asterisk, you can supply an integer argument that specifies the field width or precision. In strings containing the
%digit$ conversion character, you can indicate field width or precision by the sequence *digit$. You use a decimal digit from 1 to 9 to
indicate which argument contains an integer that specifies the field width or precision.
The conversion characters and their meanings are identical to
You must use each digit argument at least once. The results of not using an argument are undefined.
International Environment
LC_NUMERIC If this environment is set and valid, uses the international language database named in the definition to determine radix
character rules.
LANG If this environment variable is set and valid uses the international language database named in the definition to determine
collation and character classification rules. If is defined, its definition supercedes the definition of LANG.
Examples
The following example illustrates using an argument to specify field width:
nl_printf ("%1$d:%2$.*3$d:%4$.*3$d
",
hour, min, precision, sec);
The format string *3$ indicates that the third argument, which is named precision, contains the integer field width specification.
To print the language independent date and time format, use the following statement:
nl_printf (format, weekday, month, day, hour, min);
For United States of America use, could be a pointer to the following string:
"%1$s, %2$s %3$d, %4$d:%5$.2d
"
This string produces the following message:
Sunday, July 3, 10:02
For use in a German environment, could be a pointer to the following string:
"%1$s, %3$d. %2$s, %4$d:%5$.2d
"
This produces the following message:
Sonntag, 3. Juli, 10:02
See Also
intro(3int), setlocale(3), nl_scanf(3int), printf(3int), scanf(3int), printf(3s), putc(3s), scanf(3s), stdio(3s)
Guide to Developing International Software
nl_printf(3int)