Click to See Complete Forum and Search --> : Assigna string to a char buffer[]


Fotis
January 9th, 2002, 10:48 AM
I have the following code

char buffer [100];
struct sendMsg {
char func_id[20];
int data;
} send_msg;

....
...

int paramsignal=12;
sprintf(buffer,"%s 0 0 0 0 %d", "Sin", paramsignal);



How can I assign the containing of the struct member send_msg.func_id to be located in the buffer placed in the sprintf instead of the string "Sin"?
I have to use the sprintf function in my source code application.

Is this correct
sprintf(buffer,"%s 0 0 0 0 %d",send_msg.func_id, paramsignal);

Fotis
January 9th, 2002, 10:48 AM
I have the following code

char buffer [100];
struct sendMsg {
char func_id[20];
int data;
} send_msg;

....
...

int paramsignal=12;
sprintf(buffer,"%s 0 0 0 0 %d", "Sin", paramsignal);



How can I assign the containing of the struct member send_msg.func_id to be located in the buffer placed in the sprintf instead of the string "Sin"?
I have to use the sprintf function in my source code application.

Is this correct
sprintf(buffer,"%s 0 0 0 0 %d",send_msg.func_id, paramsignal);

NMTop40
January 9th, 2002, 11:00 AM
yes, it is correct


The best things come to those who rate

Gregory64
January 9th, 2002, 11:00 AM
Yes it is correct.
Do your have a problem with it ?
If so post some code

Graham
January 9th, 2002, 11:33 AM
It's fine as long as func_id is a null-terminated string.

He who breaks a thing to find out what it is, has left the path of wisdom - Gandalf