C Programming

⌘K
  1. Home
  2. Docs
  3. C Programming
  4. Data Input and Output
  5. Formatted and Unformatted I/O

Formatted and Unformatted I/O

Formatted I/O allows you to format the input or output data in a specific style using conversion specifiers.

Thank you for reading this post, don't forget to subscribe!

Functions:

  • printf() – for formatted output.
  • scanf() – for formatted input.

Example:

#include <stdio.h>

int main() {
    float num = 3.14159;
    printf("Formatted float: %.2f\n", num); // Outputs: 3.14
    return 0;
}

Unformatted I/O does not use format specifiers. It works on raw data like characters and strings.

Functions:

image 30

Example:

#include <stdio.h>

int main() {
    char ch;
    char name[30];

    printf("Enter a character: ");
    ch = getchar();  // Unformatted input
    putchar(ch);     // Unformatted output

    printf("\nEnter your name: ");
    gets(name);      // Unsafe, use fgets() in modern code
    puts(name);      // Outputs string with newline

    return 0;
}

Note: gets() is considered unsafe and has been removed from the latest C standards. Use fgets() instead.

How can we help?