Last active
March 6, 2017 11:51
-
-
Save kakopappa/6509785d5d7a257350748ee756dd2f67 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//How to to append a char array in arduino | |
char* p = (char*)malloc(sizeof(char)*12); | |
strcpy(p,"hello world"); | |
cout << p << "\r\n"; | |
p = (char*)realloc(p, sizeof(char)*24); | |
strcat(p," from Nish"); | |
cout << p << "\r\n"; | |
free(p); | |
// How to return a char* aka string from method | |
int method(char* p) { | |
if (p) { | |
strcpy(p, "I like c++"); | |
} | |
return strlen("I like c++"); | |
} | |
int main() | |
{ | |
char* par = NULL; | |
int len = method(par); | |
if (len > 0) { | |
par = (char*)malloc(len+1); | |
memset(par, 0, len + 1); | |
method(par); | |
cout << "ret at: " << par; | |
} | |
free(par); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment