由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Programming版 - 我这个读写文本文件的程序为什么第一次总是出错?
相关主题
UDP广播老是接收不到const reference in copy constructor
问一个Linux无法监听指定端口的问题array如何get set?
请教Matlab和IDL的处理数据能力差异【讨论】Linux启动时执行配置文件的顺序 (转载)
c语言如何pass变量的值请教一个C++关于输入输出的问题
4G text file哪种软件可以读?(除了ultraedit)c++如何把小数转成二进制输出到文本文件?
is dirty checking better than change listen ers一个python script同时写一万多个文本文件
zz: Is Angular 2.0 Worth It[合集] 什么办法可以把一个文本文件map到一串数字
用INADDR_ANY 怎么才能看出destination IP?C++读文本文件怎么判断换行?
相关话题的讨论汇总
话题: buf话题: listen话题: bind话题: port话题: boa
进入Programming版参与讨论
1 (共1页)
m********r
发帖数: 334
1
这段程序读boa的配置文件boa.conf,找到端口号后改写新端口,例如
Port 80
# Listen: the Internet address to bind(2) to. If you leave it out,
# it takes the behavior before 0.93.17.2, which is to bind to all
# addresses (INADDR_ANY). You only get one "Listen" directive,
变成Port 8080
# Listen: the Internet address to bind(2) to. If you leave it out,
# it takes the behavior before 0.93.17.2, which is to bind to all
# addresses (INADDR_ANY). You only get one "Listen" directive,
现在发现每次第一次修改的时候这一行没问题,但是下面的注释的#号没有了,变成
n: the Internet address to bind(2) to. If you leave it out,
# it takes the behavior before 0.93.17.2, which is to bind to all
# addresses (INADDR_ANY). You only get one "Listen" directive,
boa无法重新运行,手动改过来以后就没有问题,但是为什么第一次就不行?
system("/usr/bin/killall boa");
boa=fopen("/etc/boa.conf","rt+");
while(fgets(buf,255,boa)!= NULL)
{
if(buf[0]=='#')
continue;
p=strstr(buf,"Port ");
if(p) {
fseek(boa, (-1)*strlen(buf), SEEK_CUR);
sprintf(buf,"Port %5d\n",runtime.cm.http_port);
fputs(buf,boa);

break;
}
}
fclose(boa);

sprintf(buf, "/usr/sbin/boa -c /etc");
system(buf);
t****t
发帖数: 6806
2
because there is no way to "insert" something into a file. you have to read
the rest of the file first, insert whatever you want, and write back the
rest.

【在 m********r 的大作中提到】
: 这段程序读boa的配置文件boa.conf,找到端口号后改写新端口,例如
: Port 80
: # Listen: the Internet address to bind(2) to. If you leave it out,
: # it takes the behavior before 0.93.17.2, which is to bind to all
: # addresses (INADDR_ANY). You only get one "Listen" directive,
: 变成Port 8080
: # Listen: the Internet address to bind(2) to. If you leave it out,
: # it takes the behavior before 0.93.17.2, which is to bind to all
: # addresses (INADDR_ANY). You only get one "Listen" directive,
: 现在发现每次第一次修改的时候这一行没问题,但是下面的注释的#号没有了,变成

m*****e
发帖数: 4193
3
You cannot modify the source file. Write a new file and rename to the
original.

【在 m********r 的大作中提到】
: 这段程序读boa的配置文件boa.conf,找到端口号后改写新端口,例如
: Port 80
: # Listen: the Internet address to bind(2) to. If you leave it out,
: # it takes the behavior before 0.93.17.2, which is to bind to all
: # addresses (INADDR_ANY). You only get one "Listen" directive,
: 变成Port 8080
: # Listen: the Internet address to bind(2) to. If you leave it out,
: # it takes the behavior before 0.93.17.2, which is to bind to all
: # addresses (INADDR_ANY). You only get one "Listen" directive,
: 现在发现每次第一次修改的时候这一行没问题,但是下面的注释的#号没有了,变成

t****t
发帖数: 6806
4
oh you can modify it, just no insertion and deletion. that's hardly useful
though.

【在 m*****e 的大作中提到】
: You cannot modify the source file. Write a new file and rename to the
: original.

m********r
发帖数: 334
5
那为什么以后同样的操作后面的注释没有被覆盖?

read

【在 t****t 的大作中提到】
: because there is no way to "insert" something into a file. you have to read
: the rest of the file first, insert whatever you want, and write back the
: rest.

m********r
发帖数: 334
6
修改这种配置文件用C有什么更方便的办法?

【在 m*****e 的大作中提到】
: You cannot modify the source file. Write a new file and rename to the
: original.

t****t
发帖数: 6806
7
from "80" to "8080": 2->4, insert 2 byte (not allowed)
from "8080" to "8080": 4->4, no insertion

【在 m********r 的大作中提到】
: 那为什么以后同样的操作后面的注释没有被覆盖?
:
: read

t****t
发帖数: 6806
8
you need perl.

【在 m********r 的大作中提到】
: 修改这种配置文件用C有什么更方便的办法?
1 (共1页)
进入Programming版参与讨论
相关主题
C++读文本文件怎么判断换行?4G text file哪种软件可以读?(除了ultraedit)
怎么在c++中输出一个文本文件的内容?is dirty checking better than change listen ers
如何在VB中实现下载一个文本文件zz: Is Angular 2.0 Worth It
windows下操作大的文本文件比如1M的用INADDR_ANY 怎么才能看出destination IP?
UDP广播老是接收不到const reference in copy constructor
问一个Linux无法监听指定端口的问题array如何get set?
请教Matlab和IDL的处理数据能力差异【讨论】Linux启动时执行配置文件的顺序 (转载)
c语言如何pass变量的值请教一个C++关于输入输出的问题
相关话题的讨论汇总
话题: buf话题: listen话题: bind话题: port话题: boa