C Programming - Scanner Function
Introduction
- Presenter's name: рдЖрдирдВрдж
- Topic: Scanner Function in C
Definition of Scanner Function
- C programming provides a function called scanf.
- Usage: Used to read data from the user.
- Holds the output screen until the user enters a value.
- Found in:
stdio.h
header file.
- Meaning of stdio: Standard Input and Output.
Importance of stdio.h Header File
- Necessary for handling user input and output in C.
- Associated with features like printing messages for user inputs.
Conversion Specification
- Important when using scanf and printf functions.
- Examples:
%d
for integer values.
%f
for float values.
%s
for string values.
Example Code
Example 1: Reading an Integer
int a;
printf("Enter a number:");
sscanf("%d", &a);
printf("Value of a = %d", a);
- Garbage Value: Printed if variable is uninitialized.
Example 2: Reading Two Integers
int a, b;
printf("Enter two numbers:");
scanf("%d %d", &a, &b);
printf("Value of a = %d, Value of b = %d", a, b);
- Input example: If user enters 5 and 6.
Example 3: Reading an Integer and a Float
int a;
float b;
printf("Enter one integer and one decimal number:");
scanf("%d %f", &a, &b);
printf("Value of a = %d, Value of b = %f", a, b);
- Input example: If user enters 50 and 6.5.
Conclusion
- Further videos will cover more C programming basics.
- Reminder to subscribe for notifications.