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:

  1. "printf": Formats and prints output to the console.

  2. "scanf": Reads input from the console.

  3. "fopen": Opens a file.

  4. "fclose": Closes a file.

  5. "fprintf": Formats and writes output to a file.

  6. "fscanf": Reads input from a file.

  7. "fgets": Reads a line of text from a file or the console.

  8. "fputs": Writes a string to a file or the console.

  9. "getchar": Reads a single character from the console.

  10. "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;
}
Source‮i.www:‬giftidea.com

In 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.