P
Pedro Pinto
Hi there!
I'm creating a function that copies some information to a buffer and
enters a delimiter string "//" between results.
My issue here is when i print the buffer it appears this weird result:
cod : 2
id : 20
Buffer is
Buffer is //
final buffer is: //
What am i doing wrong for this to happen? I'm typing bellow the
function used. Thanks in advance for any help.
int criaRespCreate(int cod, int id, char *buffer){
printf("\n cod : %d", cod);
printf("\n id : %d", id);
int tam = 0;
char str[]=" // ";
int tcd = strlen(str);
// insert ID
memcpy(buffer,&id,LENGTH);
printf("\n Buffer is %s", buffer);
// Insert delimitador caracter
memcpy(buffer + tam,&str,tcd);
tam += tcd;
// inserir code
memcpy(buffer + tam,&cod,LENGTH);
tam += LENGTH;
// Insert delimitador caracter
memcpy(buffer + tam ,&str,tcd);
tam += tcd;
printf("\n Buffer is %s", buffer);
return tam;
}
I'm creating a function that copies some information to a buffer and
enters a delimiter string "//" between results.
My issue here is when i print the buffer it appears this weird result:
cod : 2
id : 20
Buffer is
Buffer is //
final buffer is: //
What am i doing wrong for this to happen? I'm typing bellow the
function used. Thanks in advance for any help.
int criaRespCreate(int cod, int id, char *buffer){
printf("\n cod : %d", cod);
printf("\n id : %d", id);
int tam = 0;
char str[]=" // ";
int tcd = strlen(str);
// insert ID
memcpy(buffer,&id,LENGTH);
printf("\n Buffer is %s", buffer);
// Insert delimitador caracter
memcpy(buffer + tam,&str,tcd);
tam += tcd;
// inserir code
memcpy(buffer + tam,&cod,LENGTH);
tam += LENGTH;
// Insert delimitador caracter
memcpy(buffer + tam ,&str,tcd);
tam += tcd;
printf("\n Buffer is %s", buffer);
return tam;
}