Copying a file on linux C
<p>I'm writing a program that simply copies an executable file in C on Linux.</p>

<pre><code>#include &lt;stdio.h&gt;


int main(int args,char*argv[]){

FILE *src1;
FILE *final;

if ((src1 = fopen("/home/exophrenik/Desktop/src1","rb")) == NULL)
{
    printf("Could not open src1\n");
    return -12;
}   

if ((final = fopen("/home/exophrenik/Desktop/final","wb")) == NULL)
{
    printf("Could not open final\n");
    return -32;
}   

int c;
while((c=fgetc(src1))!=EOF)
{
    printf("%d\n",c);
    fputc(c,final);
}

fclose(src1);
fclose(final);
return 0;
}
</code></pre>

<p>The program is properly compiled and it seems that it does it's job right. The only problem is that when I try to run the 'final' executable from the command line, I get the Permission Denied error. I recompiled the above program as sudo and also run it as sudo but it made do difference.
From my little linux experience I know that the Permission Denied is often encountered when you try to run a program with the ./ command but it is not an executable, like trying to open a txt file like that instead of using gedit to open it. </p>

<p><strong>My question is why do I get that same error when the only thing I do is copying an already working executable? Am I doing something wrong during the copy process that somehow corrupts the new file?</strong></p>