CST Assignment Added Question
CST Assignment Added Question
b) scanf()
Purpose: Reads formatted input from the standard input
(keyboard).
Usage Example:
#include <stdio.h>
int main(void) {
int age;
printf("Enter your age: ");
scanf("%d", &age);
printf("You are %d years old\n", age);
return 0;
}
2. Unformatted I/O Functions
a) getchar()
Purpose: Reads the next character (as an unsigned char cast to
int) from standard input, without any format parsing.
Usage Example:
#include <stdio.h>
int main(void) {
int c;
printf("Press a key: ");
c = getchar(); // no format string
printf("You pressed: %c\n", c);
return 0;
}
b) putchar()
Purpose: Writes a single character (given as an int) to standard
output.
Usage Example:
#include <stdio.h>
int main(void) {
char ch = 'A';
putchar(ch); // no format string
putchar('\n');
return 0;}