가장 많이 묻는 면접 질문과 답변 & 온라인 테스트
면접 준비, 온라인 테스트, 튜토리얼, 라이브 연습을 위한 학습 플랫폼

집중 학습 경로, 모의고사, 면접 준비 콘텐츠로 실력을 키우세요.

WithoutBook은 주제별 면접 질문, 온라인 연습 테스트, 튜토리얼, 비교 가이드를 하나의 반응형 학습 공간으로 제공합니다.

Chapter 9

File Handling, Command-Line Arguments, and the Preprocessor

Learn how C programs work with files, command-line input, and preprocessing directives for modular and configurable builds.

Inside this chapter

  1. File Handling Basics
  2. Reading and Writing
  3. Command-Line Arguments
  4. Preprocessor Directives
  5. Header Guards
  6. Real-World Usage Snapshot

Series navigation

Study the chapters in order for the clearest path from C basics to advanced memory, systems, debugging, and real-world development practice. Use the navigation at the bottom of each page to move smoothly through the full tutorial.

Tutorial Home

Chapter 9

File Handling Basics

#include <stdio.h>

FILE *fp = fopen("data.txt", "w");
if (fp != NULL) {
    fprintf(fp, "Hello file\n");
    fclose(fp);
}

Files are central to logging, configuration, report generation, data persistence, and system utilities. C handles files through standard library functions and file pointers.

Chapter 9

Reading and Writing

Functions such as fgetc, fgets, fscanf, fprintf, fread, and fwrite support text and binary file processing. Students should understand the difference between text-mode thinking and raw binary data handling.

Chapter 9

Command-Line Arguments

int main(int argc, char *argv[]) {
    for (int i = 0; i < argc; i++) {
        printf("%s\n", argv[i]);
    }
    return 0;
}

Command-line arguments make C programs flexible and scriptable, especially for tools, automation, and utilities.

Chapter 9

Preprocessor Directives

#include <stdio.h>
#define PI 3.14159

#ifdef DEBUG
printf("Debug mode\n");
#endif

The preprocessor is powerful but can be misused. Macros should be kept clear and intentional because debugging macro-heavy code can be difficult.

Chapter 9

Header Guards

#ifndef MATH_UTILS_H
#define MATH_UTILS_H

int add(int a, int b);

#endif

Header guards prevent multiple inclusion problems and are essential in modular C projects.

Chapter 9

Real-World Usage Snapshot

Command-line tools, log processors, build scripts, data converters, and diagnostic utilities rely heavily on file I/O and arguments. The preprocessor, meanwhile, plays a big role in portability, feature toggles, and compilation control in large C codebases.

Copyright © 2026, WithoutBook.