程序要求是打开hosts文件,找到某一个行数据进行修改.
比如hosts文件里面有一行是"192.168.0.1 testserver"
现在要修改这一行为:"192.168.0.2 testserver"
出差在外,现在手边也没有书,还请大家帮忙,谢谢.下面代码是我添加一行新数据的代码.请帮忙看看如何修改? const char *os = getenv("OS");
const char *windir = getenv("windir");
char nt[] = "Windows_NT";
char host[256];
if(strcmp(os, nt) == 0)
{
sprintf(host, "%s\\system32\\drivers\\etc\\hosts", windir);
}
else
{
sprintf(host, "%s\\hosts", windir);
}
FILE *pfile = fopen(host, "at");
if(pfile != NULL)
{
fputs("192.168.0.1 testserver\n", pfile);
fclose(pfile);
}
比如hosts文件里面有一行是"192.168.0.1 testserver"
现在要修改这一行为:"192.168.0.2 testserver"
出差在外,现在手边也没有书,还请大家帮忙,谢谢.下面代码是我添加一行新数据的代码.请帮忙看看如何修改? const char *os = getenv("OS");
const char *windir = getenv("windir");
char nt[] = "Windows_NT";
char host[256];
if(strcmp(os, nt) == 0)
{
sprintf(host, "%s\\system32\\drivers\\etc\\hosts", windir);
}
else
{
sprintf(host, "%s\\hosts", windir);
}
FILE *pfile = fopen(host, "at");
if(pfile != NULL)
{
fputs("192.168.0.1 testserver\n", pfile);
fclose(pfile);
}
解决方案 »
- MFC的透明问题
- 哪位兄比较熟悉VC2010?有问题请教
- VC读写快速Excel
- vc中如何将crystal report 8.5的报表export为word,excel,或csv files?
- 讨论:如何才能让开发的软件适应各种环境
- VS2005下编写的MFC程序的打包问题.
- 急求一个不需要用户验证的可以发信给国内邮箱的smtp的服务器地址,在线等
- vc如何读取saql server中的图像数据,并把图像显示在对话框上
- 如何才能编制或者使一个程序在windows2000登陆框(也就是输入用户名的那个),出现时就开始运行。
- 请问哪里有Visual Studio 6.0的中文MSDN下载????
- 如何从外部把数据传到派生自CPropertyPage的类中?
- 到过www.vckbase.com 的兄弟们,近来看看...这个问题!
建议你建立一个bak文件,在读的过程中,直接写bak,最后再将这个bak作为正式文件
if(!strcmp("192.168.0.1",s1))
{
//这里最好要fseek一下
fprintf("%s %s","192.168.0.2",s2);
}