strncpy() causes reset
i'm trying take parse http reply uploading data pachube.com. i'm using ehtercard.h , has function tcpreply() returns http response, is
http/1.1 200 ok
date: fri, 13 apr 2012 12:17:36 gmt
content-type: text/plain; charset=utf-8
connection: close
x-pachube-logging-key: logging.lo55oprx5dl5uwaw2nuo
x-pachuberequestid: 2ea1be6efb47aac0a0f47ec04196b14f721f605c
cache-control: max-age=0
content-length: 1
age: 0
vary: accept-encoding
according strlen() it's 308 bytes long. want use strtok (using \n delimiter) parse each line, first i'm using strncpy() prevent
a invalid conversion 'const char*' 'char*'
but sketch seems failing @ strncpy() function , reboots before strtok(). below code, can tell me doing wrong?
http/1.1 200 ok
date: fri, 13 apr 2012 12:17:36 gmt
content-type: text/plain; charset=utf-8
connection: close
x-pachube-logging-key: logging.lo55oprx5dl5uwaw2nuo
x-pachuberequestid: 2ea1be6efb47aac0a0f47ec04196b14f721f605c
cache-control: max-age=0
content-length: 1
age: 0
vary: accept-encoding
according strlen() it's 308 bytes long. want use strtok (using \n delimiter) parse each line, first i'm using strncpy() prevent
a invalid conversion 'const char*' 'char*'
but sketch seems failing @ strncpy() function , reboots before strtok(). below code, can tell me doing wrong?
code: [select]
const char* reply = ether.tcpreply(session); // part of ethercard.h library
if (reply != 0)
{
char reply2[strlen(reply)+1];
strncpy(reply2, reply, sizeof(reply)); // think arduino rebooting here
reply2[strlen(reply)] = '\0';
char delims[] = "\n";
char *result = null;
result = strtok( reply2, delims );
while( result != null )
{
serial.println(result);
result = strtok( null, delims );
}
}
if reply 308 bytes , reply2 309 bytes, that's 617 bytes of ram 1 operation.
could running out of memory?
could running out of memory?
Arduino Forum > Using Arduino > Programming Questions > strncpy() causes reset
arduino
Comments
Post a Comment