Thread: C coding help for finding the weather... NOOB

  1. #1
    Registered User
    Join Date
    Feb 2009
    Posts
    3

    C coding help for finding the weather... NOOB

    For a uni project im am trying to write a program in c that will connect to the internet and find out what the weather is. if this goes to plan i will then make it so the desktop background changes depending on the weather. ambitious i know for some1 thats picking up the basics atm.

    can someone send me in the right direction about how id go about doing this, would i have to connect to rss feeds to check the weather?

  2. #2
    Registered User
    Join Date
    Dec 2008
    Posts
    183
    u have to find the right website then you have to use either winsock or winnet to access it

  3. #3
    Technical Lead QuantumPete's Avatar
    Join Date
    Aug 2007
    Location
    London, UK
    Posts
    894
    Quote Originally Posted by philmagrill View Post
    For a uni project im am trying to write a program in c that will connect to the internet and find out what the weather is. if this goes to plan i will then make it so the desktop background changes depending on the weather. ambitious i know for some1 thats picking up the basics atm.

    can someone send me in the right direction about how id go about doing this, would i have to connect to rss feeds to check the weather?
    Why do something like that in C? It would probably be easier to program in Java or C#, which have library classes for connecting to websites, parsing html/xml content and interfacing with the WindowsAPI.
    C on the other hand has none of that.

    QuantumPete
    "No-one else has reported this problem, you're either crazy or a liar" - Dogbert Technical Support
    "Have you tried turning it off and on again?" - The IT Crowd

  4. #4
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Doesn't libcurl do a lot of that.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  5. #5
    Registered User
    Join Date
    Feb 2009
    Posts
    3
    Yeh C# makes sense but annoyingly I have to write it in C for the module. Libcurl looks interesting, will investigate cheers.

    philmagrill

  6. #6
    Registered User
    Join Date
    Feb 2009
    Posts
    3

    Lightbulb Help parsing

    Update: so far i have managed to connect to the internet and DL the bbc rss feed to the file, which i can then open up. I have almost managed to get it to edit the registry to change the desktop background.

    Atm i am try to parse the file to extract the word sunny form the XML line

    Code:
    int main(void)
    {
    char word[128];
    char *p, prefix;
    int i;
    char string[] = "<title>Saturday: sunny, Max Temp: 16&#xB0;C (61&#xB0;F), Min Temp: 4&#xB0;C (39&#xB0;F)</title>";
    
    prefix = ',';
    
    p = strchr(string, prefix);
    
    if(p == NULL) {
    printf("No %c found.\n", prefix);
    }
    else {
    i = p-string;
    //printf("Found %c at position: %d\n", prefix, i+1);
    strncpy(word, &string[0], i);
    word[i] = '\0';
    printf("Weather is: [%s]\n", word);
    }
    return 0;
    
    }
    I have managed to get it to extract everything before the comma

    insert [code]
    eg Weather is: <title>Saturday: sunny
    [\code]
    How do i get it to parse the ":" and just leave the word sunny

    (also i have just manually written in the string, how would i get it to find that line in a big XML file, would i have to parse the whole file? or can i somehow select that line no. or something?)

    Thank you

    Phil

  7. #7
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    What about having the strings you want, in a 2D char array:

    rainy, sunny, cloudy, etc.
    [0], [1] [2], etc.


    Then take your feed into a very large char array and in a loop, strstr() through the page (in the very large char array, until they find the position of the first letter of the first target word that they find.

    That would eliminate the need to parse, anything.

  8. #8
    Registered User
    Join Date
    Dec 2006
    Location
    Canada
    Posts
    3,229
    [offtopic]
    How about point a webcam out the window and get images from that?
    [/offtopic]

  9. #9
    Registered User
    Join Date
    Apr 2009
    Posts
    5
    Quote Originally Posted by cyberfish View Post
    [offtopic]
    How about point a webcam out the window and get images from that?
    [/offtopic]
    hahahah XD

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Coding noob - Hello World?
    By spadez in forum C Programming
    Replies: 6
    Last Post: 04-10-2009, 04:26 PM
  2. Replies: 9
    Last Post: 03-20-2009, 05:22 PM
  3. Coding Guideline ....!!
    By imfeelingfortun in forum Tech Board
    Replies: 8
    Last Post: 10-08-2006, 07:09 AM
  4. Before Coding
    By cyberCLoWn in forum C++ Programming
    Replies: 16
    Last Post: 12-15-2003, 02:26 AM
  5. Coding Contest....
    By Koshare in forum A Brief History of Cprogramming.com
    Replies: 46
    Last Post: 10-14-2001, 04:32 PM

Tags for this Thread