__isoc99_sscanf
#include <stdio.h>
int main() {
char input[] = "42 3.14 Hello";
int integer;
float floating_point;
char string[10];
int result = __isoc99_sscanf(input, "%d %f %s", &integer, &floating_point, string);
printf("Result: %d\n", result);
printf("Integer: %d\n", integer);
printf("Floating Point: %f\n", floating_point);
printf("String: %s\n", string);
return 0;
}
Explanation:
Include the necessary header file for standard input and output operations (
stdio.h
).Define the
main
function, which is the entry point of the program.Declare a character array
input
containing the string "42 3.14 Hello".Declare variables
integer
of typeint
,floating_point
of typefloat
, andstring
of type character array (char
).Declare a variable
result
of typeint
to store the return value of__isoc99_sscanf
.Use
__isoc99_sscanf
to parse the input string according to the specified format. The format string"%d %f %s"
indicates that the function should expect an integer, a floating-point number, and a string in the input string.Pass the addresses of variables
integer
,floating_point
, andstring
as arguments to__isoc99_sscanf
so that the parsed values can be stored in these variables.Print the result of the scanning operation using
printf
.Print the values stored in the variables
integer
,floating_point
, andstring
usingprintf
.Return 0 to indicate successful execution of the program.