How to delete an empty line from text file in C++?
<p>I've been learning programming for about a year now in college and I've learned some stuff along the way so I decided to make my very own <strong>"Host editor"</strong> program which basically edits your windows hosts file, lets you insert, remove and manage the URLs inside. :)</p>

<p>However, I've ran into problems when trying to delete a URL from the file. I'm not actually deleting it since I don't know how to do it, but I create a new empty text file and then copy all the lines except the one with the URL that I wish to delete. Sounds reasonable?</p>

<p>It appears, however, that I can't delete the URL without leaving inside a so-called <strong>"empty line"</strong>. At least not with how I've coded it... I've tried everything and I really need your help.</p>

<p>But please, use "noob friendly" language with me here, I won't understand any complicated terms :)</p>

<p>Thank you, and here's my full code:</p>

<p><a href="http://joggingbenefits.net/hcode.txt" rel="nofollow">http://joggingbenefits.net/hcode.txt</a>  </p>

<p>and here's just the part of the code that I think is messing with me (delete URL function):</p>

<pre><code>void del(int lin)  // line index
{
    FILE* fp=fopen("C:\\Windows\\System32\\drivers\\etc\\hosts","r+");
    FILE* fp1=fopen("C:\\Windows\\System32\\drivers\\etc\\hosts1","w");

    char str[200];
    int cnt=0;

    while(! feof(fp))
    {
        fgets(str,200,fp);


        if(str[0]=='#')
        {
            fputs(str,fp1);
        }
        else
        {
            if(cnt==lin)
            {               // problem. FLAG?!
                cnt++;
            }
            else
            {
                    cnt++;
                    fputs(str,fp1);
            }

        }

    }



    fclose(fp);
    fclose(fp1);

    rename("C:\\Windows\\System32\\drivers\\etc\\hosts","C:\\Windows\\System32\\drivers\\etc\\deleteme");
    rename("C:\\Windows\\System32\\drivers\\etc\\hosts1","C:\\Windows\\System32\\drivers\\etc\\hosts");
    remove("C:\\Windows\\System32\\drivers\\etc\\deleteme");

    cout &lt;&lt; endl &lt;&lt; "LINE DELETED!" &lt;&lt; endl;

}
</code></pre>
