stdio


1. Reading and Writing to Standard Input/Output

#include <stdio.h>

int main() {
  printf("Hello, world!\n");
  int x;
  scanf("%d", &x);
  printf("You entered: %d\n", x);
  return 0;
}

2. File Input/Output

#include <stdio.h>

int main() {
  FILE *fp = fopen("data.txt", "r");
  if (fp == NULL) {
    perror("Error opening file");
    return 1;
  }

  char line[100];
  while (fgets(line, sizeof(line), fp)) {
    printf("%s", line);
  }

  fclose(fp);
  return 0;
}

3. Formatted Printing

4. Error Handling

5. Binary Input/Output

6. Reading and Writing to a Pipe

7. Redirecting Standard Input/Output

8. String Formatting

9. Error Logging

10. Debugging

11. Reading from a Keyboard

12. Parsing Command-Line Arguments

13. Reading from a Socket

14. Writing to a Socket

15. Reading and Writing to a File Descriptor