I want to know how to download a file using c ?
For copying a file in c I do this.

#include<stdio.h>
#include<conio.h>
int main()
{
     FILE *inf, *ouf;
     char ch;
     inf = fopen ( "file1.ext" , "rb" );
     ouf = fopen ( "file2.ext" , "wb" );
     while( !feof (inf) )
     {
          ch = getc ( inf );
          fputc ( ch, ouf );
     }
     fclose(inf);
     fclose(ouf);
     return 0;
}

Now I have to download a file , say picture file from internet. I have it's direct link ex. http://apod.nasa.gov/apod/image/1201/LighthouseMeteor_fusco.jpg.

Now If I use the above program and in the file name I put the link instead of file1.exe it isn't working.

#include<stdio.h>
#include<conio.h>
int main()
{
     FILE *inf, *ouf;
     char ch;
     inf = fopen ( "http://apod.nasa.gov/apod/image/1201/LighthouseMeteor_fusco.jpg" , "rb" );
     ouf = fopen ( "file2.ext" , "wb" );
     while( !feof (inf) )
     {
          ch = getc ( inf );
          fputc ( ch, ouf );
     }
     fclose(inf);
     fclose(ouf);
     return 0;
}

As you can see I am new to programming. I understand that I have a lot to learn. And perhaps the method I am trying to use is the silliest method one can ever come up with. But please help me. Tell me how to do this task. If it needs a lot of explanation please direct me to the correct resources. I read some things about socket programming and other things. I spent hours on google and came up with nothing to read and understand about how to do it . I learnt about cURL but don't know how to install and use it. I would prefer to work this without using cURL but it's okay if I have to do it by using cURL only, although I would prefer to do it without cURL.

Me, I would just spawn a shell and use the wget command to download the file.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.