Thread: C library to download files

  1. #1
    Registered User
    Join Date
    Sep 2012
    Posts
    11

    C library to download files

    I have written a program that prints current temperature in my city, but it uses the cURL program to download an html page that contains temperature. I do not want a user of my program to download any additional programs. So please suggest me a C library to download files.




    Code:
    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>
    
    
    int main (void)
    {
        system ("curl -o weather.txt http://foreca.com/Russia/Saint_petersburg.html");
        /* download page we will later get weather from */
        FILE* weather = fopen ("weather.txt", "r"); /* open weather weather.txt */
        int temperature; /* variable to store temperature */
        int character; /* variable to store current character */
        char temperature_string [30] = " "; /* to store the string we will be later get temperature from */
        while (character != EOF) /* while character != EOF */
        {
            if (character == (int)'l')
            {                            
                character = fgetc (weather);
                if (character == (int)'a')
                {
                    character = fgetc (weather);
                    if (character == (int)'r')
                    {
                        character = fgetc (weather);
                        if (character == (int)'g')
                        {
                            int counter = 1; /* counter */
                            while (counter <= 11)
                            {
                                fgetc (weather);
                                counter = (counter + 1);
                            }
                            counter = 1;
                            char ad_str [2] = " ";
                            while (counter <= 4)
                            {
                                character = fgetc (weather); /* get new character from file */
                                ad_str[0] = character;
                                strcat (temperature_string, ad_str); /* concatenate temperature_string and ad_str */
                                counter = (counter + 1); /* counter++ */
                            }
                        }
                    }
                }
            }
            character = fgetc (weather);
        }
        fclose (weather); /* close the file weather.txt */
        remove ("weather.txt"); /* remove the file weather.txt */
        temperature = atoi (temperature_string); /* convert str_temperature string to int and assing result to the temperature variable */
        printf ("%i%cC in St. Petersburg, Russia", temperature, (char)248);
        /* (char)248 is degree symbol */
        return 0;
    }

  2. #2
    Registered User
    Join Date
    Jul 2012
    Location
    Australia
    Posts
    242
    I use the libcurl library. You use Curl via the terminal command line to connect to the internet for downloading or ftping or whatever.

    Libcurl is the library that your programs need to do all that, and it is what Curl is based on. I've used libcurl to write some simple curl functions, like downloading a webpage.

    libcurl - the multiprotocol file transfer library
    Last edited by cfanatic; 09-23-2012 at 06:01 AM.
    IDE: Code::Blocks | Compiler Suite for Windows: TDM-GCC (MingW, gdb)

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. c++ download files from server
    By Ideal88 in forum C++ Programming
    Replies: 1
    Last Post: 09-13-2012, 08:00 AM
  2. For C, where can I download library simpio.h?
    By cool_zzz in forum C Programming
    Replies: 5
    Last Post: 06-05-2012, 10:41 AM
  3. Download Files
    By nathanpc in forum C++ Programming
    Replies: 7
    Last Post: 07-13-2009, 03:21 AM
  4. Library that can download a HTML page?
    By Spiderbot in forum C++ Programming
    Replies: 3
    Last Post: 04-13-2006, 12:17 AM
  5. MSDN library download
    By Garfield in forum Windows Programming
    Replies: 11
    Last Post: 01-17-2002, 05:34 AM