开发者

set eof indicator in files

开发者 https://www.devze.com 2023-03-21 20:05 出处:网络
I write a program that replaces a string in file. i open file as r+ mode in C. eve开发者_运维问答rything is ok now but when the program replaces the string, filesize will be reduced, for example i hav

I write a program that replaces a string in file. i open file as r+ mode in C. eve开发者_运维问答rything is ok now but when the program replaces the string, filesize will be reduced, for example i have a file whose content is

abcDEFgh

i want to replace DEF with AA, it becomes

abcAAFgh

but there will be null space after 'h' charecter.

So here is the problem, i want to set EOF flag after the 'h' charecter like null charecter(\0) in strings.

I found an article about that in AppleScript, is it possible to do that in C?

http://docs.info.apple.com/article.html?path=AppleScript/2.1/en/as202.html


You should truncate the file using ftruncate. Saw this issue in OSx before

0

精彩评论

暂无评论...
验证码 换一张
取 消