Char Date[] = "Date: Wed, 20 Jan 2010 02:57:58 GMT";
If you wanted to pull just the time from that format you would need to call the section of the string out something like this.
Date[23]
That will pull up the 0 in the 02:57:58 of the string. The "D" at the beginning of the string is zero if i'm not mistaking. So to pull the full time you'll need to use 23-30. Now how you want to use that will dictate the way the code is laid out.
if(input = time)
{
for (int t = 23; t < 31; t++)
{
Serial.print("Time is: ");
Serial.print(Date[t]);
}
delay(2000);
}
Something like that should work for pulling the time from the string and outputting it to the serial monitor. Where whatever kind of input your looking for is asking what the time is from the string stored. Whatever your wanting those variables to be. But the format of the string would have to be such that the area being pulled from will be in the same place every time. In this case if it was a Thursday it would be Thurs and the time start area would be off by 2 places.
DISCLAIMER: I'm am still very much a noob at this. So i may be wrong here. This is from me pulling bits and pieces from examples i've played around with over the past few days and using what little i have learned. Also i'm currently at work so i don't have my arduino with me to be able to throw a quick test sketch together to see if it would work.
I got this working, now I am having trouble with an an IF statement comparing the time string to some text in quotes.
char date_time[] = "Date: Wed, 20 Jan 2010 02:57:58 GMT";
char time[6];
strncpy(time,(date_time+23),5);
time[5] = '\0';
//Even when I Serial.print(time) and it returns 02:57 the following
//statement does not return TRUE. I must not be comparing time
//to 02:57 properly.
if(time=="02:57"){
}
That doesn't do what you think it's doing. Try this:
char date_time[] = "Date: Wed, 20 Jan 2010 02:57:58 GMT";
char time[6];
strncpy(time,(date_time+23),5);
time[5] = '\0';
//Even when I Serial.print(time) and it returns 02:57 the following
//statement does not return TRUE. I must not be comparing time
//to 02:57 properly.
if(strcmp(time,"02:57") == 0) // strings match {
}
Your orignal statement was comparing pointers, i.e., memory addresses. Since the 'time' array has a different address from the address of the literal string "02:27", the comparison is false.
The C programming language doesn't have any built in string functions. It's all done with library functions, or routines you write that manipulate strings character-by-character.
Something else to keep in mind - The offset of 23 characters assumes that all the fields before the time field are of fixed length. It looks like the day name is abbreviated to 3 characters, so that should be fixed. But the 2 digit date might only be a single digit if it falls before the 10th of the month.
"Date: Wed, 20 Jan 2010 02:57:58 GMT"
"Date: Wed, 7 Jan 2010 02:57:58 GMT"
atoi() stops at the first non-digit it encounters, so the colon (':') stopped the first conversion. The end of a string has a NUL ('\0') which, being a non-digit, stopped the second conversion.