• Home
  • C Input Output Function (I/O Function)

C Input Output Function (I/O Function)

In C, the input/output (I/O) functions are used to read and write data from and to various sources, such as the keyboard, a file, or the screen. Some of the most commonly used I/O functions in C are:

  1. printf(): The printf() function is used to print a message or the value of a variable to the screen. It has the following syntax:
printf("message");

or

printf("%d", variable);
  1. scanf(): The scanf() function is used to read input from the keyboard. It has the following syntax:
scanf("%d", &variable);
  1. getchar(): The getchar() function is used to read a single character from the keyboard. It has the following syntax:
char c = getchar();
  1. putchar(): The putchar() function is used to write a single character to the screen. It has the following syntax:
putchar(c);
  1. fopen(): The fopen() function is used to open a file for reading or writing. It has the following syntax:
FILE *fp = fopen("filename", "mode");
  1. fclose(): The fclose() function is used to close a file that has been opened with the fopen() function. It has the following syntax:
fclose(fp);
  1. fgetc(): The fgetc() function is used to read a single character from a file. It has the following syntax:
char c = fgetc(fp);
  1. fputc(): The fputc() function is used to write a single character to a file. It has the following syntax:
fputc(c, fp);

These are just a few of the I/O functions available in C. There are many others, such as fscanf(), fprintf(), and gets(), that can be used to read and write data from and to various sources. It is important to carefully review the documentation for these functions to understand their syntax and usage.