This function is compatible with the following targets:
|
|
#include <stdio.h>
int printf(const char *format, ...);Parameters:
Parameters for this facility are:
The printf() function sends its output to stdout.
%), optional flag characters, an optional minimum width, an optional precision width, and the necessary, terminating conversion type. Doubling the percent sign (%%) results in the output of a single %.
An optional flag character modifies the formatting of the output; it can be left or right justified, and numerical values can be padded with zeroes or output in alternate forms. More than one optional flag character can be used in a conversion specification. "Length Modifiers And Conversion Specifiers For Formatted Output Functions" describes the flag characters.
NOTE
minimum field width allowed in MSL Standard Libraries is 509 characters.
The terminating character, the conversion type, specifies the conversion applied to the conversion specification's matching argument "Length Modifiers And Conversion Specifiers For Formatted Output Functions," describes the conversion type characters.
The listing "Example of AltiVec Printf Extensions" demonstrates their use.
Length Modifiers And Conversion Specifiers For Formatted Output Functions:"Wide Character and Byte Character Stream Orientation"
Example of printf() usage.:#include <stdio.h>
int main(void)
{
int i = 25;
char c = 'M';
short int d = 'm';
static char s[] = "Metrowerks!";
static char pas[] = "\pMetrowerks again!";
float f = 49.95;
double x = 1038.11005;
int count;
printf("%s printf() demonstration:\n%n", s, &count);
printf("The last line contained %d characters\n",count);
printf("Pascal string output: %#20s\n", pas);
printf("%-4d %x %06x %-5o\n", i, i, i, i);
printf("%*d\n", 5, i);
printf("%4c %4u %4.10d\n", c, c, c);
printf("%4c %4hu %3.10hd\n", d, d, d);
printf("$%5.2f\n", f);
printf("%5.2f\n%6.3f\n%7.4f\n", x, x, x);
printf("%*.*f\n", 8, 5, x);
return 0;
}
The output is:
Metrowerks! printf() demonstration:
The last line contained 36 characters
Pascal string output: Metrowerks again!
25 19 000019 31
25
M 77 0000000077
m 109 0000000109
$49.95
1038.11
1038.110
1038.1101
1038.11005
Example of AltiVec Printf Extensions:
#include <stdio.h>
int main(void)
{
vector signed char s =
(vector signed char)(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16);
vector unsigned short us16 =
(vector unsigned short)('a','b','c','d','e','f','g','h');
vector signed int sv32 =
(vector signed int)(100, 2000, 30000, 4);
vector signed int vs32 =
(vector signed int)(0, -1, 2, 3);
vector float flt32 =
(vector float)(1.1, 2.22, 3.3, 4.444);
printf("s = %vd\n", s);
printf("s = %,vd\n", s);
printf("vector=%@vd\n", "\nvector=", s);
// c specifier so no space is added.
printf("us16 = %vhc\n", us16);
printf("sv32 = %,5lvd\n", sv32);
printf("vs32 = 0x%@.8lvX\n", ", 0x", vs32);
printf("flt32 = %,5.2vf\n", flt32);
return 0;
}
The Result is:
s = 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
s = 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16
vector=1
vector=2
vector=3
vector=4
vector=5
vector=6
vector=7
vector=8
vector=9
vector=10
vector=11
vector=12
vector=13
vector=14
vector=15
vector=16
us16 = abcdefgh
sv32 = 100, 2000,30000, 4
vs32 = 0x00000000, 0xFFFFFFFF, 0x00000002, 0x00000003
flt32 = 1.10, 2.22, 3.30, 4.44
[ First ] [ Previous ] [ Next ] [ Last ] [ Manuals ]
Visit the Metrowerks website at: http://www.metrowerks.com
For assistance contact Metrowerks Technical Support at: cw_support@metrowerks.com
Copyright © 2000, Metrowerks Corp. All rights reserved.
Last updated: August 16, 2000