C Board  

Go Back   C Board > General Programming Boards > C Programming

Reply
 
LinkBack Thread Tools Display Modes
Old 02-25-2009, 02:52 PM   #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?
philmagrill is offline   Reply With Quote
Old 02-25-2009, 03:17 PM   #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
lolguy is offline   Reply With Quote
Old 02-26-2009, 04:00 AM   #3
Technical Lead
 
QuantumPete's Avatar
 
Join Date: Aug 2007
Location: London, UK
Posts: 723
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
QuantumPete is offline   Reply With Quote
Old 02-26-2009, 04:07 AM   #4
Kernel hacker
 
Join Date: Jul 2007
Location: Farncombe, Surrey, England
Posts: 15,686
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.
matsp is offline   Reply With Quote
Old 02-26-2009, 06:53 AM   #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
philmagrill is offline   Reply With Quote
Old 04-18-2009, 06:26 AM   #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
philmagrill is offline   Reply With Quote
Old 04-18-2009, 07:59 AM   #7
Registered User
 
Join Date: Sep 2006
Posts: 2,512
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.
Adak is offline   Reply With Quote
Old 04-18-2009, 12:42 PM   #8
Registered User
 
Join Date: Dec 2006
Posts: 1,780
[offtopic]
How about point a webcam out the window and get images from that?
[/offtopic]
cyberfish is offline   Reply With Quote
Old 04-18-2009, 03:46 PM   #9
Registered User
 
Join Date: Apr 2009
Posts: 4
Quote:
Originally Posted by cyberfish View Post
[offtopic]
How about point a webcam out the window and get images from that?
[/offtopic]
hahahah XD
blkhockeypro19 is offline   Reply With Quote
Reply

Tags
connection, internet, noob, weather

Thread Tools
Display Modes

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Coding noob - Hello World? spadez C Programming 6 04-10-2009 04:26 PM
The chicken and the egg problem... trying to learn coding but having trouble starting mothergoose729 Tech Board 9 03-20-2009 05:22 PM
Coding Guideline ....!! imfeelingfortun Tech Board 8 10-08-2006 07:09 AM
Before Coding cyberCLoWn C++ Programming 16 12-15-2003 02:26 AM
Coding Contest.... Koshare A Brief History of Cprogramming.com 46 10-14-2001 04:32 PM


All times are GMT -6. The time now is 08:44 AM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.0 RC2

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22