# fopen() ํ•จ์ˆ˜

PHP๋ฅผ ๊ณต๋ถ€ํ•˜๋˜ ์ค‘ ํŒŒ์ผ์„ ์ œ์–ดํ•  ์ผ์ด ์ƒ๊ฒผ๋‹ค.

C์–ธ์–ด์—์„œ file์„ ๋‹ค๋ฃจ๋˜ ๊ฒƒ๊ณผ ๊ฑฐ์˜ ๋˜‘๊ฐ™์ด fopen()๋ฅผ ํ™œ์šฉํ•˜๋ฉด ๋” ์‰ฌ์šด file ์ œ์–ด๊ฐ€ ๊ฐ€๋Šฅํ–ˆ๋‹ค.

C์–ธ์–ด๋ฅผ ์‚ฌ์šฉํ•  ๋•Œ ์ž์ฃผ ํ—ท๊ฐˆ๋ ธ๋˜ r / w / r+ / w+ / a ์˜ต์…˜์„ ์ •๋ฆฌํ•ด๋‘๋ ค๊ณ  ํ•œ๋‹ค.


stack overflow (opens new window) ์— ๋‚˜์™€ ๊ฐ™์€ ๊ณ ๋ฏผ์„ ํ•œ ๊ฐœ๋ฐœ์ž์˜ ์งˆ๋ฌธ์„ ์ธ์šฉํ•˜๊ฒ ๋‹ค.

# Difference between r+ and w+ in fopen()

In fopen("myfile", "r+") what is the difference between the "r+" and "w+" open mode? I read this

"r" Open a text file for reading.
"w" Open a text file for writing, truncating an an existing file to zero length, or creating the file if it does not exist.

"r+" Open a text file for update (that is, for both reading and writing).
"w+" Open a text file for update (reading and writing), first truncating the file to zero length if it exists or creating the file if it does not exist.

I mean the difference is that if I open the file with "w+", the file will be erased first?


๋‹ต๋ณ€ ์ค‘ ์ด ์ด๋ฏธ์ง€๋ฅผ ์ฐธ๊ณ ํ•˜๋ฉด ํ™•์‹คํžˆ ์ •๋ฆฌ๊ฐ€ ๋œ๋‹ค.

img

Last Updated: 6/18/2023, 2:13:15 PM