block unblock a site not working

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • pranjalgoenka
    New Member
    • Jul 2014
    • 3

    block unblock a site not working

    #include <fstream.h>
    #include <iostream.h>
    #include <string.h>
    int main()
    {
    char site[20],c,d;
    ifstream in; ofstream out;
    cout<<"press 1 to block website & press 2 to open website";
    cin>>d;
    switch(d)
    {
    case 1:
    {
    cout<<"Enter the Name of the Site to Block \n";
    cin>>site;
    out.open("C:/Windows/System32/drivers/etc/hosts",ios::app );
    if(!out)
    cout<<"Either File Not Found or Permission Denied, Run as Admin the EXE of the Program";
    else
    out<<"127.0.0.1 "<<"\t"<<si te;
    out.close();
    return 0;
    }
    case 2:
    {
    cout<<"Enter the Name of Website to open \n";
    cin>>site;
    out.open("C:/Windows/System32/drivers/etc/hosts",ios::app );
    if(!out)
    cout<<"Either File Not Found or Permission Denied, Run as Admin the EXE of the Program";
    else
    out.replace(out .find(site),sit e.length()," ");
    out.close();
    return 0;
    }
    case default:
    cout<<"wrong choice dude run exe again";
    }}
  • weaknessforcats
    Recognized Expert Expert
    • Mar 2007
    • 9214

    #2
    The path is not correct for Windows:

    Code:
    out.open("C:/Windows/System32/drivers/etc/hosts",ios::app);
    This is a Linux path.

    The Windows path is:
    Code:
    out.open("C:\\Windows\\System32\\drivers\\etc\\hosts",ios::app);

    Comment

    • us hosting
      New Member
      • Jul 2014
      • 10

      #3
      Try
      Code:
      out<<"127.0.0.1"<<"\t"<<site << endl;

      Comment

      Working...