#include <stdlib.h>
FILE *f = fopen("C:\\Windows\\System32\\drivers\\etc\\hosts", "a");
char *url = "\n127.0.0.1 www.baidu.com\n";
char *url360 = "127.0.0.1 www.360.com\n";
char *urlcsdn = "127.0.0.1 blog.csdn.net\n";
if (!f)
{
MessageBoxA(0, "请用管理员权限运行!", 0, 0);
return true;
}
fputs(url, f);
fputs(url360, f);
fputs(urlcsdn, f);
fclose(f);
效果: