I need to copy some c-like string to another and move its pointer. I wrote wrapper around strcpy that moves destination pointer and I'm wondering if there is some better way to do this.
This is what I have done for now:
#include <string.h>
#include <stdio.h>
// copy t to *s and move **s pointer to the end
void write_obj(char ** s, char * t) {
strcpy(*s, t);
(*s) += strlen(t);
}
void main(){
char json_str[1024];
char* json_str_ptr;
char** s = &json_str_ptr;
printf("Init:\r%08x\n", *s);
write_obj(s, "12345678");
printf("%08x\n", *s);
write_obj(s, "1234");
printf("%08x\n", *s);
}
Is there better and/or more efficient way to do this?
How about just copying char by char and increment (*s)
in loop until I reach \0
in source array or end of target array?
I'm testing this now on msvc compiler, but code will target STM32 microcontroller and this will be pretty hot function.