C programming - standard library stdio.h
The "stdio.h" header file in C programming provides the standard input/output functions used for reading and writing data to files, devices, and the console.
Some of the commonly used functions in "stdio.h" include:
"printf": Formats and prints output to the console.
"scanf": Reads input from the console.
"fopen": Opens a file.
"fclose": Closes a file.
"fprintf": Formats and writes output to a file.
"fscanf": Reads input from a file.
"fgets": Reads a line of text from a file or the console.
"fputs": Writes a string to a file or the console.
"getchar": Reads a single character from the console.
"putchar": Writes a single character to the console.
Here is an example of using the "stdio.h" header file in a C program:
#include <stdio.h>
int main() {
int num;
printf("Enter a number: ");
scanf("%d", &num);
printf("You entered: %d\n", num);
FILE *fp = fopen("example.txt", "w");
if (fp == NULL) {
printf("Error opening file\n");
return 1;
}
fprintf(fp, "This is a line written to the file\n");
fclose(fp);
return 0;
}Sourcei.www:giftidea.comIn this example, the "stdio.h" header file functions are used to read input from the console, write output to the console, open a file, write output to a file, and close the file. The "scanf" function is used to read a number from the console, and the "printf" function is used to print the number to the console. The "fopen" function is used to open a file for writing, and the "fprintf" function is used to write a line of text to the file. The "fclose" function is used to close the file. The output of the program will be:
Enter a number: 42 You entered: 42
Note that the behavior of the functions in "stdio.h" is platform-dependent, and they may differ between different implementations of C.
