This function is compatible with the following targets:
|
|
#include <stdio.h>
int scanf(const char *format, ...);Parameters:
Parameters for this facility are:
The scanf() function reads text and converts the text read to programmer specified types.
The last character, the conversion type, specifies the kind of conversion requested. "Length Modifiers And Conversion Specifiers For Formatted Input Functions," describes the conversion type characters.
The listing "Example of AltiVec Scanf Extensions" demonstrates their use.
Length Modifiers And Conversion Specifiers For Formatted Input Functions:"Wide Character and Byte Character Stream Orientation"
Example of scanf() usage.:#include <stdio.h>
int main(void)
{
int i;
unsigned int j;
char c;
char s[40];
double x;
printf("Enter an integer surrounded by ! marks\n");
scanf("!%d!", &i);
printf("Enter three integers\n");
printf("in hexadecimal, octal, or decimal.\n");
// note that 3 integers are read, but only the last two
// are assigned to i and j
scanf("%*i %i %ui", &i, &j);
printf("Enter a character and a character string.\n");
scanf("%c %10s", &c, s);
printf("Enter a floating point value.\n");
scanf("%lf", &x);
return 0;
}
Output:
Enter an integer surrounded by ! marks
!94!
Enter three integers
in hexadecimal, octal, or decimal.
1A 6 24
Enter a character and a character string.
Enter a floating point value.
A
Sounds like 'works'!
3.4
Example of AltiVec Scanf Extensions:
#include <stdio.h>
int main(void)
{
vector signed char v8, vs8;
vector unsigned short v16;
vector signed long v32;
vector float vf32;
sscanf("1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16", "%vd", &v8);
sscanf("1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16", "%,vd", &vs8);
sscanf("abcdefgh", "%vhc", &v16);
sscanf("1, 4, 300, 400", "%,3lvd", &v32);
sscanf("1.10, 2.22, 3.333, 4.4444", "%,5vf", &vf32);
return 0;
}
The Result is:
v8 = 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16;
vs8 = 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16;
v16 = 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h'
v32 = 1, 4, 300, 400
vf32 = 1.1000, 2.2200, 3.3330, 4.4444
[ 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