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; }



2Likes
LinkBack URL
About LinkBacks


