logo

English

이곳의 프로그래밍관련 정보와 소스는 마음대로 활용하셔도 좋습니다. 다만 쓰시기 전에 통보 정도는 해주시는 것이 예의 일것 같습니다. 질문이나 오류 수정은 siseong@gmail.com 으로 주세요. 감사합니다.

fopen 파일 열기 모드 옵션 정리

by digipine posted Nov 02, 2017
?

Shortcut

PrevPrev Article

NextNext Article

Larger Font Smaller Font Up Down Go comment Print
?

Shortcut

PrevPrev Article

NextNext Article

Larger Font Smaller Font Up Down Go comment Print

fopen의 파일 열기 옵션은 자꾸 잊어먹어서 그때 그때 찾이 보기도 불편해서 정리해 보았다.


"r" : 읽기 전용 모드. 파일이 없으면 NULL return.
"w" :쓰기 전용 모드. 파일이 없으면 생성되고 있으면 내용이 없어진다.
"a" : append모드. 파일이 없으면 생성. 이미 존재하는 파일 끝부분에 file pointer가 위치하게 되며 이 위치부터 뒷쪽으로만 write가능. 읽기는 불가능. fseek등으로 이 부분보다 앞으로 file pointer를 이동시키면 어떻게 될까 ? 아래 내용으로 봐서는 fseek등으로 file pointer를 이동하여도 이와 상관없이 파일 끝부분에 write가 되는 것으로 생각됨.

Opening a file in append mode (a in the mode) causes all subsequent writes to the file to be forced to the current end-of-file, regardless of previous calls to the fseek() function.

"r+" : 읽고 쓰기 모드, 파일이 없으면 NULL return.
"w+" : 읽고 쓰기 모드 단, 파일이 없으면 만들고 있으면 기존 내용을 지움. write를 먼저 한 후 동일 파일 포인터로 읽기 수행이 필요한 경우 사용. 보통은 읽기 전용, 혹은 쓰기 전용으로 fopen하므로 w+가 필요한 일은 별로 없을 듯.
"a+" : append모드, 읽고 쓰기 가능. 파일이 이미 존재할 경우 그 파일의 끝부분에서부터 추가된 내용을 쓴다. 읽기는 fseek로 지정한 file pointer위치에서 가능하나 쓰기는 파일 끝부분에서만 가능.

When a file is opened with update mode (+ in the mode), both input and output may be performed on the associated stream

TAG •

List of Articles
No. Subject Author Date Views
23 [C/C++] 현재시간 구하기 digipine 2017.10.28 2212
22 C++에서 extern의 역할, 기능 digipine 2017.10.29 2656
21 STL MAP 예제로 공부하기 digipine 2017.10.29 5204
20 MD5 파일 변조 검사 관련 소스 (리눅스/Windows) digipine 2017.10.29 2613
19 brute-force 알고리즘을 이용한 패턴 위치 찾기 digipine 2017.10.29 1501
18 Solaris 10에 개발 Tool (gcc,vim,gdb) 설치 digipine 2017.10.29 1257
17 Solaris에서 pmap을 이용하여 백그라운드 프로세스 메모리 크기 구하기 digipine 2017.10.29 28599
16 Callback in C++ 와 Delegate 차이점 digipine 2017.11.01 2525
15 C를 이용한 객체지향 프로그래밍 digipine 2017.11.01 568
14 C 에서 Overloading 구현 digipine 2017.11.01 1790
13 wchar_t에 대하여 digipine 2017.11.01 7343
12 Unix C/C++ Input and Output Function Reference digipine 2017.11.01 88076
11 [shared lib] so 동적 라이브러리 만들기와 사용법 - 리눅스 digipine 2017.11.01 6434
10 Introduce to Singly-linked List file digipine 2017.11.01 1288
9 Linux C 언어로 Shell 명령어 실행하기 digipine 2017.11.01 22587
8 [linux] zlib build 방법 digipine 2017.11.01 1483
7 [Linux] Pthread 사용법, Thread 동기화 총정리 digipine 2017.11.01 294062
6 make -j 옵션으로 컴파일 속도 최적화 하기 digipine 2017.11.01 2759
» fopen 파일 열기 모드 옵션 정리 digipine 2017.11.02 3894
4 C++ 컴파일 오류(error): variable 'std::istringstream sstream' has initializer but incomplete type digipine 2017.11.02 21077
Board Pagination Prev 1 2 Next
/ 2