I originally posted about strong termination as i'd had problems with that myself. On closer examination it's probably not that - now that i've got the bottom of why my program was going wrong with string termination.
Since the topic has raised here and will appear in future searches, it seems a good idea to set the record stright about strings.
Example 1 :
http.get("http://stuff",httpdata);
This examples call http.get with two character pointers, one to a location in readonly flash memory, and one in RAM. The Flash memory wil lhave initialised by the compiler which understands string representation and so will have.terminated correctly.
Example 2 :
char url[80] = "http://stuff";
http.get(url,httpdata);
In this example url is a pointer to the first of 80 characters in RAM. It is being assigned from a string literal in flash which will also have been terminated correctly when the compiler created, so a correctly terminated string will be copied to url.
Example 3 :
char url[80];
int val = 42;
sprintf(foo,"http://stuff/bar.php?arg=%d",val);
In this example url is also a pointer to the first of 80 characters in RAM, and when sprintf formats the string and places it in url , it will also be terminated correctly.
Example 4 : (the one I got wrong)
char url[80] = {'h','t','t','p',':','/','/','s','t','u','f','f'};
In this example url is still a pointer to the first of 80 characters in RAM, but it is not being assigned with a string, the contents are being manipulated manually. In this scenario there is no string termination, and so a printf of url would show the string described followed by the (most likely random) content of the rest of the array.
This is the scenario in which adding a null terminator after the last character would be important if the array was to be treated as a string later.
Hope that helps clear things up about strings.
Cheers,
Chris
Hi guys, I know I'm probably being very, very stupid here, but I'm trying to use the HTTP Client library and I'm not getting anywhere!
I have Orange stripe going to 'RD-', Orange to 'RD+', Green stripe to 'TD-' and Green to 'TD+' but when I boot my mbed the LEDs flash the outer pair then the inner pair repeatedly and nothing seems to happen! What is my mbed trying to tell me?
Thanks in advance