|
-
January 9th, 2002, 11:48 AM
#1
Assigna string to a char buffer[]
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);
-
January 9th, 2002, 12:00 PM
#2
Re: Assigna string to a char buffer[]
yes, it is correct
The best things come to those who rate
-
January 9th, 2002, 12:00 PM
#3
Re: Assigna string to a char buffer[]
Yes it is correct.
Do your have a problem with it ?
If so post some code
-
January 9th, 2002, 12:33 PM
#4
Re: Assigna string to a char buffer[]
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
Correct is better than fast. Simple is better than complex. Clear is better than cute. Safe is better than insecure.
-- Sutter and Alexandrescu, C++ Coding Standards
Programs must be written for people to read, and only incidentally for machines to execute.
-- Harold Abelson and Gerald Jay Sussman
The cheapest, fastest and most reliable components of a computer system are those that aren't there.
-- Gordon Bell
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|