Nov 27, 2024
stdio.h
or standard input-output library in C contains methods for input and output.scanf()
scanf("%X", &variableOfXType);
%X
: Format specifier indicating the data type of the variable.&
: Address operator, indicating where the input should be stored in memory.printf()
printf("%X", variableOfXType);
%X
: Format specifier indicating the data type of the variable.scanf("%d", &intVariable);
printf("%d", intVariable);
scanf("%f", &floatVariable);
printf("%f", floatVariable);
scanf("%c", &charVariable);
printf("%c", charVariable);
#include<stdio.h>
int main() {
int num;
char ch;
float f;
// Integer
printf("Enter the integer: ");
scanf("%d", &num);
printf("\nEntered integer is: %d", num);
// Float
while((getchar()) != '\n'); // Clearing buffer
printf("\n\nEnter the float: ");
scanf("%f", &f);
printf("\nEntered float is: %f", f);
// Character
printf("\n\nEnter the Character: ");
scanf("%c", &ch);
printf("\nEntered character is: %c", ch);
return 0;
}
scanf("%s", stringVariable);
printf("%s", stringVariable);
#include<stdio.h>
int main() {
char str[50];
// Reading a word
printf("Enter the Word: ");
scanf("%s", str);
printf("\nEntered Word is: %s", str);
// Reading a sentence
printf("\n\nEnter the Sentence: ");
scanf("%[^\n]s", str);
printf("\nEntered Sentence is: %s", str);
return 0;
}
scanf()
and printf()
facilitates effective data handling in C programming.