Sponsored Content
Full Discussion: Printf conversion specifiers
Top Forums Programming Printf conversion specifiers Post 302885106 by yifangt on Thursday 23rd of January 2014 01:45:00 PM
Old 01-23-2014
How stupid to use the scanf format for printf!------Thanks, Corona!
I got it now:
Code:
printf("%d\n%%\n%c\n%5s\n%c\n%s\n\n", i, c, string, string[5], string+5);

$ ./a.out
Please input a line:
45 , ignore_this, % C read_in_this**

45
%
C
read_in_this**
i
in_this**

Quote:
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!
If print string, use the address of the string array(cf: string+5); if print the char of the string, use the subscription (string[5]) explicitly.

Last edited by yifangt; 01-23-2014 at 03:18 PM.. Reason: quote reply
This User Gave Thanks to yifangt For This Post:
 

10 More Discussions You Might Find Interesting

1. Programming

printf

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

printf

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

Need help with printf

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

AWK printf help

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

The meaning of %s in printf

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

Printf problem

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

error: expected declaration specifiers or '...' before syslog

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

Printf command

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

NAWK conversion of hexadecimal input to decimal output via printf, I am close I can feel it

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

Printf statement for currency conversion

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
XPRINTF_DOMAIN(3)					   BSD Library Functions Manual 					 XPRINTF_DOMAIN(3)

NAME
copy_printf_domain, free_printf_domain, new_printf_domain, register_printf_domain_function, register_printf_domain_render_std -- extensible printf domains SYNOPSIS
#include <printf.h> printf_domain_t copy_printf_domain(printf_domain_t domain); void free_printf_domain(printf_domain_t domain); printf_domain_t new_printf_domain(void); int register_printf_domain_function(printf_domain_t domain, int spec, printf_function *render, printf_arginfo_function *arginfo);, void *context int register_printf_domain_render_std(printf_domain_t domain, const char *specs); DESCRIPTION
A printf domain is an extensible printf (see xprintf(5)) structure defining a set of conversion specifiers that will be used in calls to the routines discussed in xprintf(3) and xprintf_comp(3). Domains can be modified independently of one another, and do not affect the behavior of the normal printf calls in printf(3). To create a new domain, call new_printf_domain(); the standard POSIX conversion specifiers are defined by default. To make a copy of an existing domain, use copy_printf_domain(). When a domain is no longer needed, call free_printf_domain() to release the associated memory. The register_printf_domain_function() function is used to add, modify or remove conversion specifiers for a given domain. The spec argument is the specifier character, which can be any printable (non-control) ASCII character, except for those characters that are used as flag/option characters. The set of flag/option characters includes the space character, and the following: # $ ' * + , - . 0 1 2 3 4 5 6 7 8 9 : ; L _ h j l q t v z Two user-defined callback function must also be given; see xprintf(5) for a description of these callback functions and an example of use. Setting either or both callbacks to NULL deletes the given specifier from the domain. Note that while it is permissible to redefine the standard conversion specifiers, it is not usually recommended as it may cause confusion. The register_printf_domain_render_std() function is used to add pre-defined conversion specifiers to the given domain. The specs argument is a null-terminated C string containing one or more of the following specifier characters: H Hex dump. The 'H' specifier takes two arguments; the first is a pointer to the data to dump, while the second argument is the length of the data, given as type unsigned. Normally, 16 characters are displayed per line, as pairs of hex characters separated by spaces. Speci- fying a field width less than 16 will display that number of characters per line. Setting the '+' (showsign) flag will prefix each line with the hex offset of the beginning character in that line. Setting the '#' (alternate form) flag will postfix an ASCII representation to each line, with '.' representing non-printable characters. M Errno. The 'M' specifier displayed the text representation of the given int argument, expected to be a valid errno value (as returned by strerror(3)). Invalid errno values are represent by the ``errno='' string followed by the decimal and hex values of the argument. Q Quoted. The 'Q' specifier displays a null-terminated string argument as a C string, with leading and trailing double quotes. Newlines, carriage-returns and tabs are represented by ' ', ' ' and ' ', respectively, while backslashes and double quotes are preceeded with a backslash. All other whitespace characters not including space itself (those in which isspace(3) returns true) are displayed as octal escape sequences (a backslash followed by three octal digits). All other characters print as themselves. T time_t/timeval/timespec. The 'T' specifier displays the three types of time values as a single decimal value. The argument should be a pointer to the time value to be converted. Setting the appropriate flags indicates which type is indicated: ll The 'll' (long long) flag indicates the argument points to a struct timespec structure. The default precision is 9. l The 'l' (long) flag indicates the argument points to a struct timeval structure. The default precision is 6. (none) By default, the argument points to a time_t value. The default precision is 0 (the fractional part is not displayed). If the '#' (alternate form) flag is specified, the value is displayed in years, days, hours, minutes and seconds, as in: ``3y123d21h59m59s.987654'' (zero values are not displayed at all). Note that the years are 365 days (no leap days). V String vis. The 'V' specifier uses strvisx(3) to display the null-terminated C string argument. The precision value can be used to limit the amount of the string that is processed (defaults to the entire string). Flag values can be used to obtain different encodings: + The '+' (showsign) flag uses the ``VIS_WHITE | VIS_HTTPSTYLE'' flag value to strvisx(3). 0 The '0' (leading zero) flag uses the ``VIS_WHITE | VIS_OCTAL'' flag value to strvisx(3). # The '#' (alternate form) flag uses the ``VIS_WHITE'' flag value to strvisx(3). (none) The default flag value to strvisx(3) is ``VIS_WHITE | VIS_CSTYLE | VIS_OCTAL''. RETURN VALUES
The new_printf_domain() and copy_printf_domain() functions return the new domain, or NULL on failure (usually out of memory condition). The register_printf_domain_function() and register_printf_domain_render_std() return zero on success and -1 on failure (usually due to an improper specifier character or out of memory condition). SEE ALSO
printf(3), strvisx(3), xprintf(3), xprintf_comp(3), xprintf(5) Darwin Aug 19, 2012 Darwin
All times are GMT -4. The time now is 09:13 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy